@carbonid1/design-system 4.3.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -1
- package/src/Badge/Badge.tsx +53 -0
- package/src/Badge/Badge.types.ts +17 -0
- package/src/Tooltip/Tooltip.tsx +1 -1
- package/src/index.ts +3 -2
- package/src/ProgressRing/ProgressRing.test.tsx +0 -51
- package/src/Switch/Switch.test.tsx +0 -31
- package/src/Switch/Switch.tsx +0 -41
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbonid1/design-system",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Shared React UI primitives + design tokens (themes, postcss config)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -75,11 +75,13 @@
|
|
|
75
75
|
"@types/react": "^19.2.14",
|
|
76
76
|
"@types/react-dom": "^19.2.3",
|
|
77
77
|
"@vitejs/plugin-react": "^6.0.1",
|
|
78
|
+
"@vitest/browser-playwright": "^4.1.4",
|
|
78
79
|
"class-variance-authority": "^0.7.1",
|
|
79
80
|
"clsx": "^2.1.1",
|
|
80
81
|
"jsdom": "^29.0.2",
|
|
81
82
|
"lucide-react": "^1.8.0",
|
|
82
83
|
"next-themes": "^0.4.6",
|
|
84
|
+
"playwright": "^1.59.1",
|
|
83
85
|
"react": "^19.2.5",
|
|
84
86
|
"react-dom": "^19.2.5",
|
|
85
87
|
"react-hotkeys-hook": "^5.2.4",
|
|
@@ -96,6 +98,8 @@
|
|
|
96
98
|
"build-storybook": "storybook build",
|
|
97
99
|
"test": "vitest --run",
|
|
98
100
|
"test:watch": "vitest",
|
|
101
|
+
"test:storybook": "vitest --project=storybook",
|
|
102
|
+
"test:run:storybook": "vitest run --project=storybook",
|
|
99
103
|
"postinstall": "node scripts/install-skill.mjs"
|
|
100
104
|
}
|
|
101
105
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { cn } from '../helpers/cn/cn'
|
|
4
|
+
import { cva } from 'class-variance-authority'
|
|
5
|
+
import { X } from 'lucide-react'
|
|
6
|
+
import type { BadgeProps } from './Badge.types'
|
|
7
|
+
|
|
8
|
+
const badgeVariants = cva(
|
|
9
|
+
'inline-flex max-w-full min-w-0 items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium',
|
|
10
|
+
{
|
|
11
|
+
variants: {
|
|
12
|
+
variant: {
|
|
13
|
+
default: 'bg-muted text-muted-foreground',
|
|
14
|
+
primary: 'bg-primary-border/30 text-primary',
|
|
15
|
+
success: 'bg-success/15 text-success-foreground',
|
|
16
|
+
attention: 'bg-attention-muted text-attention-foreground',
|
|
17
|
+
destructive: 'bg-destructive/15 text-destructive',
|
|
18
|
+
highlight: 'bg-highlight-muted text-highlight-foreground',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
defaultVariants: { variant: 'default' },
|
|
22
|
+
},
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
const Badge = ({
|
|
26
|
+
className,
|
|
27
|
+
variant,
|
|
28
|
+
onRemove,
|
|
29
|
+
removeLabel,
|
|
30
|
+
children,
|
|
31
|
+
...props
|
|
32
|
+
}: BadgeProps) => {
|
|
33
|
+
const resolvedRemoveLabel =
|
|
34
|
+
removeLabel ?? (typeof children === 'string' ? `Remove ${children}` : 'Remove')
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<span className={cn(badgeVariants({ variant }), className)} {...props}>
|
|
38
|
+
{onRemove ? <span className="truncate">{children}</span> : children}
|
|
39
|
+
{onRemove && (
|
|
40
|
+
<button
|
|
41
|
+
type="button"
|
|
42
|
+
aria-label={resolvedRemoveLabel}
|
|
43
|
+
onClick={onRemove}
|
|
44
|
+
className="-me-0.5 inline-flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-full opacity-70 hover:opacity-100 focus-visible:ring-2 focus-visible:ring-current focus-visible:ring-offset-1 focus-visible:ring-offset-transparent focus-visible:outline-none"
|
|
45
|
+
>
|
|
46
|
+
<X className="size-3" aria-hidden="true" />
|
|
47
|
+
</button>
|
|
48
|
+
)}
|
|
49
|
+
</span>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { Badge, badgeVariants }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react'
|
|
2
|
+
import type { VariantProps } from 'class-variance-authority'
|
|
3
|
+
import type { badgeVariants } from './Badge'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `variant` communicates emphasis, not meaning — always pair it with
|
|
7
|
+
* descriptive text content so the badge isn't relying on color alone.
|
|
8
|
+
*/
|
|
9
|
+
type BadgeProps = HTMLAttributes<HTMLSpanElement> &
|
|
10
|
+
VariantProps<typeof badgeVariants> & {
|
|
11
|
+
/** When set, renders an inline dismiss button after the label. */
|
|
12
|
+
onRemove?: () => void
|
|
13
|
+
/** A11y label for the dismiss button. Defaults to `Remove ${children}` when children is a string, otherwise `Remove`. */
|
|
14
|
+
removeLabel?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type { BadgeProps }
|
package/src/Tooltip/Tooltip.tsx
CHANGED
|
@@ -94,7 +94,7 @@ export const Tooltip = ({
|
|
|
94
94
|
<div
|
|
95
95
|
role="tooltip"
|
|
96
96
|
style={maxWidth ? { maxWidth } : undefined}
|
|
97
|
-
className={`absolute left-1/2 z-50 -translate-x-1/2 ${maxWidth ? 'whitespace-normal' : 'whitespace-nowrap'} bg-foreground text-background pointer-events-none flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs shadow-lg ${positionClasses}`}
|
|
97
|
+
className={`absolute left-1/2 z-50 -translate-x-1/2 ${maxWidth ? 'w-max whitespace-normal' : 'whitespace-nowrap'} bg-foreground text-background pointer-events-none flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs shadow-lg ${positionClasses}`}
|
|
98
98
|
>
|
|
99
99
|
{label}
|
|
100
100
|
{shortcut && (
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export { Badge, badgeVariants } from './Badge/Badge'
|
|
2
|
+
export type { BadgeProps } from './Badge/Badge.types'
|
|
3
|
+
|
|
1
4
|
export { Button, buttonVariants } from './Button/Button'
|
|
2
5
|
export type { ButtonProps } from './Button/Button.types'
|
|
3
6
|
|
|
@@ -8,8 +11,6 @@ export { ProgressRing } from './ProgressRing/ProgressRing'
|
|
|
8
11
|
|
|
9
12
|
export { Slider } from './Slider/Slider'
|
|
10
13
|
|
|
11
|
-
export { Switch } from './Switch/Switch'
|
|
12
|
-
|
|
13
14
|
export { ContextMenu } from './ContextMenu/ContextMenu'
|
|
14
15
|
|
|
15
16
|
export { Select } from './Select/Select'
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/react'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
3
|
-
import { ProgressRing } from './ProgressRing'
|
|
4
|
-
import { CIRCUMFERENCE } from './ProgressRing.consts'
|
|
5
|
-
|
|
6
|
-
describe('ProgressRing', () => {
|
|
7
|
-
it('renders zero dashoffset at 0% progress', () => {
|
|
8
|
-
render(<ProgressRing progress={0} colorClass="text-primary" label="Empty" testId="ring" />)
|
|
9
|
-
const circle = screen.getByTestId('ring')
|
|
10
|
-
const offset = Number(circle.getAttribute('stroke-dashoffset'))
|
|
11
|
-
expect(offset).toBeCloseTo(CIRCUMFERENCE, 1)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('renders correct dashoffset at 50% progress', () => {
|
|
15
|
-
render(<ProgressRing progress={0.5} colorClass="text-primary" label="Half" testId="ring" />)
|
|
16
|
-
const circle = screen.getByTestId('ring')
|
|
17
|
-
const offset = Number(circle.getAttribute('stroke-dashoffset'))
|
|
18
|
-
expect(offset).toBeCloseTo(CIRCUMFERENCE * 0.5, 1)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('renders zero dashoffset at 100% progress', () => {
|
|
22
|
-
render(<ProgressRing progress={1} colorClass="text-success" label="Full" testId="ring" />)
|
|
23
|
-
const circle = screen.getByTestId('ring')
|
|
24
|
-
const offset = Number(circle.getAttribute('stroke-dashoffset'))
|
|
25
|
-
expect(offset).toBeCloseTo(0, 1)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('applies colorClass to fill circle', () => {
|
|
29
|
-
render(<ProgressRing progress={0.5} colorClass="text-success" label="Test" testId="ring" />)
|
|
30
|
-
const circle = screen.getByTestId('ring')
|
|
31
|
-
expect(circle.classList.toString()).toContain('text-success')
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('applies pulse animation when animate is true', () => {
|
|
35
|
-
render(<ProgressRing progress={0.5} colorClass="text-primary" label="Pulsing" animate />)
|
|
36
|
-
const svg = screen.getByRole('img', { hidden: true })
|
|
37
|
-
expect(svg.classList.toString()).toContain('animate-buffer-pulse')
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('does not apply pulse animation when animate is false', () => {
|
|
41
|
-
render(<ProgressRing progress={0.5} colorClass="text-primary" label="Idle" />)
|
|
42
|
-
const svg = screen.getByRole('img', { hidden: true })
|
|
43
|
-
expect(svg.classList.toString()).not.toContain('animate-buffer-pulse')
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('sets aria-label from label prop', () => {
|
|
47
|
-
render(<ProgressRing progress={0.5} colorClass="text-primary" label="42 paragraphs ready" />)
|
|
48
|
-
const svg = screen.getByRole('img', { hidden: true })
|
|
49
|
-
expect(svg.getAttribute('aria-label')).toBe('42 paragraphs ready')
|
|
50
|
-
})
|
|
51
|
-
})
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { cleanup, render, screen } from '@testing-library/react'
|
|
2
|
-
import userEvent from '@testing-library/user-event'
|
|
3
|
-
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
4
|
-
import { Switch } from './Switch'
|
|
5
|
-
|
|
6
|
-
afterEach(cleanup)
|
|
7
|
-
|
|
8
|
-
describe('Switch', () => {
|
|
9
|
-
it('renders as a switch with the correct checked state', () => {
|
|
10
|
-
render(<Switch checked={true} onChange={() => {}} aria-label="Toggle" />)
|
|
11
|
-
expect(screen.getByRole('switch')).toBeChecked()
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('calls onChange when clicked', async () => {
|
|
15
|
-
const user = userEvent.setup()
|
|
16
|
-
const onChange = vi.fn()
|
|
17
|
-
render(<Switch checked={false} onChange={onChange} aria-label="Toggle" />)
|
|
18
|
-
|
|
19
|
-
await user.click(screen.getByRole('switch'))
|
|
20
|
-
expect(onChange).toHaveBeenCalledWith(true)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('does not call onChange when disabled', async () => {
|
|
24
|
-
const user = userEvent.setup()
|
|
25
|
-
const onChange = vi.fn()
|
|
26
|
-
render(<Switch checked={false} onChange={onChange} disabled aria-label="Toggle" />)
|
|
27
|
-
|
|
28
|
-
await user.click(screen.getByRole('switch'))
|
|
29
|
-
expect(onChange).not.toHaveBeenCalled()
|
|
30
|
-
})
|
|
31
|
-
})
|
package/src/Switch/Switch.tsx
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { cn } from '../helpers/cn/cn'
|
|
4
|
-
import { Switch as SwitchPrimitive } from '@base-ui/react/switch'
|
|
5
|
-
|
|
6
|
-
type SwitchProps = {
|
|
7
|
-
checked: boolean
|
|
8
|
-
onChange: (checked: boolean) => void
|
|
9
|
-
disabled?: boolean
|
|
10
|
-
'aria-label'?: string
|
|
11
|
-
className?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const Switch = ({
|
|
15
|
-
checked,
|
|
16
|
-
onChange,
|
|
17
|
-
disabled,
|
|
18
|
-
'aria-label': ariaLabel,
|
|
19
|
-
className,
|
|
20
|
-
}: SwitchProps) => (
|
|
21
|
-
<SwitchPrimitive.Root
|
|
22
|
-
checked={checked}
|
|
23
|
-
onCheckedChange={checked => onChange(checked)}
|
|
24
|
-
disabled={disabled}
|
|
25
|
-
aria-label={ariaLabel}
|
|
26
|
-
className={cn(
|
|
27
|
-
'relative inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full transition-colors',
|
|
28
|
-
'focus-visible:ring-ring/50 focus-visible:border-ring focus-visible:ring-3 focus-visible:outline-hidden',
|
|
29
|
-
checked ? 'bg-primary' : 'bg-input',
|
|
30
|
-
disabled && 'pointer-events-none opacity-50',
|
|
31
|
-
className,
|
|
32
|
-
)}
|
|
33
|
-
>
|
|
34
|
-
<SwitchPrimitive.Thumb
|
|
35
|
-
className={cn(
|
|
36
|
-
'bg-background pointer-events-none block size-[18px] rounded-full shadow-sm transition-transform',
|
|
37
|
-
checked ? 'translate-x-5.5' : 'translate-x-[3px]',
|
|
38
|
-
)}
|
|
39
|
-
/>
|
|
40
|
-
</SwitchPrimitive.Root>
|
|
41
|
-
)
|