You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shared.tsx 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import type { ComponentProps, FC } from 'react'
  2. import classNames from '@/utils/classnames'
  3. const baseStyle = 'py-[3px]'
  4. export type SliceContainerProps = ComponentProps<'span'>
  5. export const SliceContainer: FC<SliceContainerProps> = (
  6. {
  7. ref,
  8. ...props
  9. },
  10. ) => {
  11. const { className, ...rest } = props
  12. return <span {...rest} ref={ref} className={classNames(
  13. 'group mr-1 select-none align-bottom text-sm',
  14. className,
  15. )} />
  16. }
  17. SliceContainer.displayName = 'SliceContainer'
  18. export type SliceLabelProps = ComponentProps<'span'> & { labelInnerClassName?: string }
  19. export const SliceLabel: FC<SliceLabelProps> = (
  20. {
  21. ref,
  22. ...props
  23. },
  24. ) => {
  25. const { className, children, labelInnerClassName, ...rest } = props
  26. return <span {...rest} ref={ref} className={classNames(
  27. baseStyle,
  28. 'bg-state-base-hover-alt px-1 uppercase text-text-tertiary group-hover:bg-state-accent-solid group-hover:text-text-primary-on-surface',
  29. className,
  30. )}>
  31. <span className={classNames('text-nowrap', labelInnerClassName)}>
  32. {children}
  33. </span>
  34. </span>
  35. }
  36. SliceLabel.displayName = 'SliceLabel'
  37. export type SliceContentProps = ComponentProps<'span'>
  38. export const SliceContent: FC<SliceContentProps> = (
  39. {
  40. ref,
  41. ...props
  42. },
  43. ) => {
  44. const { className, children, ...rest } = props
  45. return <span {...rest} ref={ref} className={classNames(
  46. baseStyle,
  47. 'whitespace-pre-line break-all bg-state-base-hover px-1 leading-7 group-hover:bg-state-accent-hover-alt group-hover:text-text-primary',
  48. className,
  49. )}>
  50. {children}
  51. </span>
  52. }
  53. SliceContent.displayName = 'SliceContent'
  54. export type SliceDividerProps = ComponentProps<'span'>
  55. export const SliceDivider: FC<SliceDividerProps> = (
  56. {
  57. ref,
  58. ...props
  59. },
  60. ) => {
  61. const { className, ...rest } = props
  62. return <span {...rest} ref={ref} className={classNames(
  63. baseStyle,
  64. 'bg-state-base-active px-[1px] text-sm group-hover:bg-state-accent-solid',
  65. className,
  66. )}>
  67. {/* use a zero-width space to make the hover area bigger */}
  68. &#8203;
  69. </span>
  70. }
  71. SliceDivider.displayName = 'SliceDivider'