Button.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. // Button: token-styled button atom. Variants map to the --dsw-alias-button-*
  2. // fill families; no framework imports, all behavior via props.
  3. import type { ButtonHTMLAttributes, ReactNode } from 'react'
  4. import clsx from 'clsx'
  5. import css from './Button.module.css'
  6. /** Visual variant, each backed by its --dsw-alias-button-* token family. */
  7. export type ButtonVariant = 'primary' | 'ghost' | 'outline' | 'toolbar'
  8. /**
  9. * Render a button.
  10. * @param props.variant - visual family (default 'ghost').
  11. * @param props.size - 'md' 36px capsule (figma Button) or 'sm' 28px compact.
  12. * @param props.icon - optional leading 16px icon node.
  13. * @returns the button element; native button attributes pass through.
  14. */
  15. export function Button({ variant = 'ghost', size = 'md', icon, className, children, ...rest }: {
  16. variant?: ButtonVariant
  17. size?: 'md' | 'sm'
  18. icon?: ReactNode
  19. className?: string | undefined
  20. children?: ReactNode
  21. } & ButtonHTMLAttributes<HTMLButtonElement>) {
  22. return (
  23. <button type="button" className={clsx(css.button, css[variant], css[size], className)} {...rest}>
  24. {icon != null && <span className={css.icon}>{icon}</span>}
  25. {children}
  26. </button>
  27. )
  28. }