-
Notifications
You must be signed in to change notification settings - Fork 218
feat(custom): implement SubscriptionTable scaffolding and register global module exports #1660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import CheckIcon from '@mui/icons-material/Check'; | ||
| import CloseIcon from '@mui/icons-material/Close'; | ||
| import { Box, Button, Table, TableBody, TableHead, Typography } from '@mui/material'; | ||
| import React from 'react'; | ||
|
|
||
| // Strict TypeScript interfaces to handle dynamic table data | ||
| export interface SubscriptionTableProps { | ||
| title?: string; | ||
| features?: PlanFeature[]; | ||
| onPlanSelect?: (planType: 'free' | 'team' | 'enterprise') => void; | ||
| featuresLabel?: string; | ||
| freePlanLabel?: string; | ||
| freePlanButtonLabel?: string; | ||
| teamPlanLabel?: string; | ||
| teamPlanButtonLabel?: string; | ||
| enterprisePlanLabel?: string; | ||
| enterprisePlanButtonLabel?: string; | ||
| } | ||
|
|
||
| export const SubscriptionTable: React.FC<SubscriptionTableProps> = ({ | ||
| title = 'Subscription Plans Comparison', | ||
| features = [], | ||
| onPlanSelect, | ||
| featuresLabel = 'Features', | ||
| freePlanLabel = 'Free Plan', | ||
| freePlanButtonLabel = 'Get Started', | ||
| teamPlanLabel = 'Team Plan', | ||
| teamPlanButtonLabel = 'Upgrade', | ||
| enterprisePlanLabel = 'Enterprise Plan', | ||
| enterprisePlanButtonLabel = 'Contact Us' | ||
| }) => { | ||
|
Comment on lines
+7
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To support internationalization (i18n) and localization, avoid hardcoding UI strings (such as table headers and button labels) in shared components. Expose these strings as configurable props with default values to maintain backward compatibility. Additionally, default the References
|
||
| // Helper function to render true/false values as Crisp Icons or Text | ||
| const renderValue = (value: boolean | string) => { | ||
| if (typeof value === 'boolean') { | ||
| return value ? ( | ||
| <CheckIcon color="success" data-testid="check-icon" /> | ||
| ) : ( | ||
| <CloseIcon color="error" data-testid="close-icon" /> | ||
| ); | ||
| } | ||
| return ( | ||
| <Typography variant="body2" sx={{ fontWeight: 500 }}> | ||
| {value} | ||
| </Typography> | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <Box sx={{ width: '100%', my: 4 }}> | ||
| {title && ( | ||
| <Typography | ||
| variant="h4" | ||
| component="h2" | ||
| sx={{ | ||
| mb: 3, | ||
| fontWeight: 700, | ||
| fontFamily: 'Qanelas Soft, sans-serif' // Figma semantic typography mapping | ||
| }} | ||
| > | ||
| {title} | ||
| </Typography> | ||
| )} | ||
|
|
||
| <StyledTableContainer> | ||
| <Table sx={{ minWidth: 650 }} aria-label="subscription comparison table"> | ||
| <TableHead> | ||
| <StyledHeaderRow> | ||
| <StyledTableCell sx={{ fontWeight: 'bold', fontSize: '1.1rem' }}> | ||
| {featuresLabel} | ||
| </StyledTableCell> | ||
| <StyledTableCell align="center" sx={{ fontWeight: 'bold', fontSize: '1.1rem' }}> | ||
| {freePlanLabel} | ||
| <Box sx={{ mt: 1 }}> | ||
| <Button size="small" variant="outlined" onClick={() => onPlanSelect?.('free')}> | ||
| {freePlanButtonLabel} | ||
| </Button> | ||
| </Box> | ||
| </StyledTableCell> | ||
| <StyledTableCell align="center" sx={{ fontWeight: 'bold', fontSize: '1.1rem' }}> | ||
| {teamPlanLabel} | ||
| <Box sx={{ mt: 1 }}> | ||
| <Button | ||
| size="small" | ||
| variant="contained" | ||
| color="primary" | ||
| onClick={() => onPlanSelect?.('team')} | ||
| > | ||
| {teamPlanButtonLabel} | ||
| </Button> | ||
| </Box> | ||
| </StyledTableCell> | ||
| <StyledTableCell align="center" sx={{ fontWeight: 'bold', fontSize: '1.1rem' }}> | ||
| {enterprisePlanLabel} | ||
| <Box sx={{ mt: 1 }}> | ||
| <Button | ||
| size="small" | ||
| variant="contained" | ||
| color="secondary" | ||
| onClick={() => onPlanSelect?.('enterprise')} | ||
| > | ||
| {enterprisePlanButtonLabel} | ||
| </Button> | ||
| </Box> | ||
| </StyledTableCell> | ||
| </StyledHeaderRow> | ||
| </TableHead> | ||
|
|
||
| <TableBody> | ||
| {features.map((row, index) => ( | ||
| <TableRow | ||
| key={index} | ||
| sx={{ | ||
| '&:last-child td, &:last-child th': { border: 0 }, | ||
| '&:hover': { backgroundColor: 'action.hover' } | ||
| }} | ||
| > | ||
| <FeatureHeaderCell component="th" scope="row"> | ||
| {row.featureName} | ||
| </FeatureHeaderCell> | ||
| <StyledTableCell align="center">{renderValue(row.freePlan)}</StyledTableCell> | ||
| <StyledTableCell align="center">{renderValue(row.teamPlan)}</StyledTableCell> | ||
| <StyledTableCell align="center">{renderValue(row.enterprisePlan)}</StyledTableCell> | ||
| </TableRow> | ||
| ))} | ||
| </TableBody> | ||
| </Table> | ||
| </StyledTableContainer> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| SubscriptionTable.displayName = 'SubscriptionTable'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './SubscriptionTable'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { Paper, TableCell, TableRow } from '@mui/material'; | ||
| import { styled } from '@mui/material/styles'; | ||
|
|
||
| // Custom Styled Container aligned with Sistent Theme | ||
| export const StyledTableContainer = styled(Paper)(({ theme }) => ({ | ||
| borderRadius: theme.shape.borderRadius * 2, | ||
| overflow: 'hidden', | ||
| boxShadow: theme.shadows[2], | ||
| border: `1px solid ${theme.palette.divider}` | ||
| })); | ||
|
|
||
| // Custom Styled Header Row | ||
| export const StyledHeaderRow = styled(TableRow)(({ theme }) => ({ | ||
| backgroundColor: theme.palette.mode === 'light' ? '#f9fafb' : '#1e1e1e' | ||
| })); | ||
|
|
||
| // Custom Styled Table Cell for Typography token enforcement | ||
| export const StyledTableCell = styled(TableCell)(({ theme }) => ({ | ||
| fontFamily: 'Open Sans, sans-serif', | ||
| borderColor: theme.palette.divider, | ||
| fontWeight: 500 | ||
| })); | ||
|
|
||
| // Feature Name Column styling (High Emphasis) | ||
| export const FeatureHeaderCell = styled(StyledTableCell)(() => ({ | ||
| fontFamily: 'Qanelas Soft, sans-serif', | ||
| fontWeight: 700, | ||
| color: 'text.primary' | ||
| })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import the custom styled components from
./styleand clean up the unused MUI imports (Paper,TableCell,TableContainer,TableRow) to keep the code clean and leverage the custom styling defined for this component.