@times-design-system/components-react
v1.19.1
Published
Times Design System components
Maintainers
Readme
@times-design-system/components-react
React component library for the Times Design System. Provides a collection of accessible, production-ready UI components with semantic token integration and multiple export patterns for optimal tree-shaking.
Installation
yarn add @times-design-system/components-react @times-design-system/theme-cssreact and react-dom (18 or 19) are peer dependencies.
Load the component styles and a theme once, at the root of your app:
import '@times-design-system/theme-css/variables.css'; // tokens, typography utilities, fonts
import '@times-design-system/components-react/styles.css'; // component stylesQuick Start
Import All Components
import {
Button,
Input,
Link,
Toast
} from '@times-design-system/components-react';
export function App() {
return (
<Button intent="primary" size="large">
Click me
</Button>
);
}Tree-Shakeable Imports
For better bundle optimization, import individual components:
import { Button } from '@times-design-system/components-react/Button';
import { Input } from '@times-design-system/components-react/Input';
import { IconButton } from '@times-design-system/components-react/IconButton';Available Components
AdContainer, Banner, Button, ButtonContainer, Checkbox, CheckboxList, CheckboxListItem, Chip, DialogBox, Divider, Dropdown, DropdownMenu, Grid, GridItem, Icon, IconButton, Image, Input, InputHelperMessage, Label, Link, ListItem, Switch, Tab, TabGroup, Tag, Text, Toast, Tooltip.
Each is also available as a subpath, e.g. @times-design-system/components-react/Button.
Icons
Icon props (iconName, iconLeft, iconRight, leftIcon, rightIcon, icon) accept either an icon component or a registered icon name. Only the handful of icons the components use internally are registered by default, so your bundle contains just the icons you use.
import { Button, registerIcons } from '@times-design-system/components-react';
import Search from '@times-design-system/icons/filled_search';
import ArrowRight from '@times-design-system/icons/filled_arrow_right';
// Pass a component…
<Button iconLeft={Search} label="Search" />;
// …or register names once at startup and keep using strings
registerIcons({ filled_search: Search, filled_arrow_right: ArrowRight });
<Button
iconLeft="filled_search"
iconRight="filled_arrow_right"
label="Search"
/>;To make every icon name available (the pre-2.0 behaviour, adds the full icon set — about 650 KB gzipped — to your bundle):
import '@times-design-system/components-react/icons-all';Component Examples
Button
import { Button } from '@times-design-system/components-react/Button';
// Standard button
<Button intent="primary" size="large">
Submit
</Button>
// Button with icons
<Button iconLeft="filled_arrow_left" iconRight="filled_arrow_right">
Navigate
</Button>
// Button as link
<Button href="/page" target="_blank">
Learn More
</Button>
// Different intents
<Button intent="primary">Primary</Button>
<Button intent="secondary">Secondary</Button>
<Button intent="negative">Delete</Button>
// Different states
<Button state="hover">Hover</Button>
<Button state="disabled">Disabled</Button>
<Button state="loading">Loading</Button>IconButton
import { IconButton } from '@times-design-system/components-react/IconButton';
// Icon button
<IconButton iconName="filled_add" ariaLabel="Add item" />
// As link
<IconButton
href="https://example.com"
iconName="filled_arrow_right"
target="_blank"
/>
// Different sizes and intents
<IconButton size="small" intent="primary" />
<IconButton size="large" intent="secondary" />Input
import { Input } from '@times-design-system/components-react/Input';
<Input type="text" placeholder="Enter text..." disabled={false} />;Text
import { Text } from '@times-design-system/components-react/Text';
<Text variant="heading" size="large">
Heading
</Text>
<Text variant="body">
Body text
</Text>Component Props
All components follow the Times Design System guidelines:
Common Props
- intent:
'primary' | 'secondary' | 'negative'- Visual style variant - size:
'small' | 'medium' | 'large'- Component size - state:
'base' | 'hover' | 'pressed' | 'loading' | 'disabled' | 'focus'- Interaction state - disabled:
boolean- Disabled state - className:
string- Additional CSS classes
Link Support
Button and IconButton support link rendering:
- href:
string- URL to navigate to - target:
'_blank' | '_self' | '_parent' | '_top'- Link target - rel:
string- Link relationship (auto-set for security when needed)
Styling
Components render tds-* class names. Their styles ship as a single stylesheet, @times-design-system/components-react/styles.css, which must be imported once (see Installation). Nothing is injected at runtime, so styles work with server rendering and strict Content Security Policies.
Colours, typography and spacing come from CSS custom properties supplied by @times-design-system/theme-css.
Accessibility
All components follow WAI-ARIA standards:
- Semantic HTML elements (button, a, input, etc.)
- ARIA labels and roles where appropriate
- Keyboard navigation support
- Focus management
- Loading and disabled states properly announced
<IconButton iconName="filled_add" ariaLabel="Add new item" />TypeScript Support
Full TypeScript support with exported interfaces:
import {
Button,
type ButtonProps
} from '@times-design-system/components-react/Button';
interface MyComponentProps extends ButtonProps {
customProp?: string;
}
export const MyComponent: React.FC<MyComponentProps> = (props) => {
return <Button {...props} />;
};Development
Building
npm run buildGenerates:
- ES modules in
dist/ - CommonJS bundles for Node.js
- TypeScript declarations
- Shared code chunks for deduplication
This build is then published to npm (https://www.npmjs.com/package/@times-design-system/components-react), where components can be installed to your codebase as a using versioned dependency; e.g. "@times-design-system/components-react": "1.0.0"
Development Server
npm run devWatches source files and rebuilds on changes.
Testing
npm run testPackage Structure
The package uses modern module resolution:
- ES Modules:
dist/Component/Component.js - CommonJS:
dist/Component/Component.cjs - Type Definitions:
dist/Component/Component.d.ts(ESM) and.d.cts(CommonJS) - Styles:
dist/index.css, exported as./styles.css - Shared Dependencies:
dist/shared/*(deduplicated code)
react, react-dom and @times-design-system/icons are never bundled. The exports map is generated from the component folders by scripts/react-components/sync-exports.mjs; add a component by creating src/<Name>/<Name>.tsx, exporting it from src/index.ts and running that script.
Browser Support
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
Contributing
This package is part of the Times Design System. For contribution guidelines, see the main repository README.
License
ISC
