@appica/ui-react 1.1.0 → 1.3.0
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/CHANGELOG.md +62 -14
- package/README.md +1 -1
- package/agent-rules.md +2 -2
- package/appica.css +1 -1
- package/dist/components/accordion/accordion.js +1 -0
- package/dist/components/accordion/accordion.js.map +1 -1
- package/dist/components/alert/alert.d.ts +1 -1
- package/dist/components/alert/alert.js +1 -0
- package/dist/components/alert/alert.js.map +1 -1
- package/dist/components/alert-dialog/alert-dialog.js +2 -1
- package/dist/components/alert-dialog/alert-dialog.js.map +1 -1
- package/dist/components/autocomplete/autocomplete.js +3 -2
- package/dist/components/autocomplete/autocomplete.js.map +1 -1
- package/dist/components/avatar/avatar.d.ts +1 -1
- package/dist/components/avatar/avatar.js +1 -0
- package/dist/components/avatar/avatar.js.map +1 -1
- package/dist/components/background-pattern/background-pattern-interactive.d.ts +2 -1
- package/dist/components/background-pattern/background-pattern-interactive.d.ts.map +1 -1
- package/dist/components/background-pattern/background-pattern-interactive.js +3 -1
- package/dist/components/background-pattern/background-pattern-interactive.js.map +1 -1
- package/dist/components/background-pattern/background-pattern-shared.d.ts +3 -2
- package/dist/components/background-pattern/background-pattern-shared.d.ts.map +1 -1
- package/dist/components/background-pattern/background-pattern-shared.js +47 -15
- package/dist/components/background-pattern/background-pattern-shared.js.map +1 -1
- package/dist/components/background-pattern/background-pattern.d.ts +1 -1
- package/dist/components/background-pattern/background-pattern.d.ts.map +1 -1
- package/dist/components/background-pattern/background-pattern.js +12 -3
- package/dist/components/background-pattern/background-pattern.js.map +1 -1
- package/dist/components/background-pattern/index.js +1 -0
- package/dist/components/background-pattern/index.js.map +1 -1
- package/dist/components/badge/badge.d.ts +2 -2
- package/dist/components/badge/badge.js +2 -1
- package/dist/components/badge/badge.js.map +1 -1
- package/dist/components/border-beam/border-beam.js +1 -0
- package/dist/components/border-beam/border-beam.js.map +1 -1
- package/dist/components/breadcrumb/breadcrumb.js +2 -1
- package/dist/components/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/components/button/button-variants.d.ts +2 -2
- package/dist/components/button/button-variants.js +2 -1
- package/dist/components/button/button-variants.js.map +1 -1
- package/dist/components/button/button.js +1 -0
- package/dist/components/button/button.js.map +1 -1
- package/dist/components/button/index.js +1 -0
- package/dist/components/button/index.js.map +1 -1
- package/dist/components/button-group/button-group-context.js +1 -0
- package/dist/components/button-group/button-group-context.js.map +1 -1
- package/dist/components/button-group/button-group.js +1 -0
- package/dist/components/button-group/button-group.js.map +1 -1
- package/dist/components/calendar/calendar.js +2 -1
- package/dist/components/calendar/calendar.js.map +1 -1
- package/dist/components/card/card.js +2 -1
- package/dist/components/card/card.js.map +1 -1
- package/dist/components/carousel/carousel.d.ts +3 -11
- package/dist/components/carousel/carousel.d.ts.map +1 -1
- package/dist/components/carousel/carousel.js +25 -1
- package/dist/components/carousel/carousel.js.map +1 -1
- package/dist/components/checkbox/checkbox.js +1 -0
- package/dist/components/checkbox/checkbox.js.map +1 -1
- package/dist/components/checkbox-group/checkbox-group.js +1 -0
- package/dist/components/checkbox-group/checkbox-group.js.map +1 -1
- package/dist/components/chip/chip.d.ts +1 -1
- package/dist/components/chip/chip.js +1 -0
- package/dist/components/chip/chip.js.map +1 -1
- package/dist/components/collapsible/collapsible.js +1 -0
- package/dist/components/collapsible/collapsible.js.map +1 -1
- package/dist/components/color-area/color-area.d.ts.map +1 -1
- package/dist/components/color-area/color-area.js +2 -0
- package/dist/components/color-area/color-area.js.map +1 -1
- package/dist/components/color-picker/color-picker.js +1 -0
- package/dist/components/color-picker/color-picker.js.map +1 -1
- package/dist/components/color-slider/color-slider.d.ts.map +1 -1
- package/dist/components/color-slider/color-slider.js +2 -0
- package/dist/components/color-slider/color-slider.js.map +1 -1
- package/dist/components/color-swatch/color-swatch.d.ts +1 -1
- package/dist/components/color-swatch/color-swatch.js +1 -0
- package/dist/components/color-swatch/color-swatch.js.map +1 -1
- package/dist/components/color-swatch-picker/color-swatch-picker.d.ts +1 -1
- package/dist/components/color-swatch-picker/color-swatch-picker.js +2 -1
- package/dist/components/color-swatch-picker/color-swatch-picker.js.map +1 -1
- package/dist/components/combobox/combobox.d.ts +5 -4
- package/dist/components/combobox/combobox.d.ts.map +1 -1
- package/dist/components/combobox/combobox.js +5 -3
- package/dist/components/combobox/combobox.js.map +1 -1
- package/dist/components/compare-slider/compare-slider.d.ts +50 -0
- package/dist/components/compare-slider/compare-slider.d.ts.map +1 -0
- package/dist/components/compare-slider/compare-slider.js +321 -0
- package/dist/components/compare-slider/compare-slider.js.map +1 -0
- package/dist/components/context-menu/context-menu.d.ts.map +1 -1
- package/dist/components/context-menu/context-menu.js +7 -1
- package/dist/components/context-menu/context-menu.js.map +1 -1
- package/dist/components/copy-button/copy-button.d.ts +3 -1
- package/dist/components/copy-button/copy-button.d.ts.map +1 -1
- package/dist/components/copy-button/copy-button.js +5 -4
- package/dist/components/copy-button/copy-button.js.map +1 -1
- package/dist/components/countdown/countdown.js +1 -0
- package/dist/components/countdown/countdown.js.map +1 -1
- package/dist/components/date-field/date-field.js +1 -0
- package/dist/components/date-field/date-field.js.map +1 -1
- package/dist/components/date-picker/date-picker.js +1 -0
- package/dist/components/date-picker/date-picker.js.map +1 -1
- package/dist/components/dialog/dialog.js +2 -1
- package/dist/components/dialog/dialog.js.map +1 -1
- package/dist/components/drawer/drawer.js +1 -0
- package/dist/components/drawer/drawer.js.map +1 -1
- package/dist/components/dropdown-menu/dropdown-menu.d.ts +13 -2
- package/dist/components/dropdown-menu/dropdown-menu.d.ts.map +1 -1
- package/dist/components/dropdown-menu/dropdown-menu.js +115 -4
- package/dist/components/dropdown-menu/dropdown-menu.js.map +1 -1
- package/dist/components/field/field.js +1 -0
- package/dist/components/field/field.js.map +1 -1
- package/dist/components/fieldset/fieldset.js +1 -0
- package/dist/components/fieldset/fieldset.js.map +1 -1
- package/dist/components/form/form.js +1 -0
- package/dist/components/form/form.js.map +1 -1
- package/dist/components/gradient-glow/gradient-glow.d.ts +6 -1
- package/dist/components/gradient-glow/gradient-glow.d.ts.map +1 -1
- package/dist/components/gradient-glow/gradient-glow.js +4 -2
- package/dist/components/gradient-glow/gradient-glow.js.map +1 -1
- package/dist/components/input/index.js +1 -0
- package/dist/components/input/index.js.map +1 -1
- package/dist/components/input/input-variants.d.ts +1 -1
- package/dist/components/input/input-variants.js +1 -0
- package/dist/components/input/input-variants.js.map +1 -1
- package/dist/components/input/input.js +1 -0
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/kbd/kbd.js +1 -0
- package/dist/components/kbd/kbd.js.map +1 -1
- package/dist/components/loader/loader.js +1 -0
- package/dist/components/loader/loader.js.map +1 -1
- package/dist/components/menubar/menubar.js +1 -0
- package/dist/components/menubar/menubar.js.map +1 -1
- package/dist/components/meter/meter.js +1 -0
- package/dist/components/meter/meter.js.map +1 -1
- package/dist/components/navigation/index.js +1 -0
- package/dist/components/navigation/index.js.map +1 -1
- package/dist/components/navigation/navigation-context.js +1 -0
- package/dist/components/navigation/navigation-context.js.map +1 -1
- package/dist/components/navigation/navigation-link-variants.d.ts +2 -2
- package/dist/components/navigation/navigation-link-variants.js +2 -1
- package/dist/components/navigation/navigation-link-variants.js.map +1 -1
- package/dist/components/navigation/navigation-link.js +1 -0
- package/dist/components/navigation/navigation-link.js.map +1 -1
- package/dist/components/navigation/navigation.js +1 -0
- package/dist/components/navigation/navigation.js.map +1 -1
- package/dist/components/navigation-menu/navigation-menu.js +2 -1
- package/dist/components/navigation-menu/navigation-menu.js.map +1 -1
- package/dist/components/number-field/number-field.js +1 -0
- package/dist/components/number-field/number-field.js.map +1 -1
- package/dist/components/otp-field/otp-field.js +1 -0
- package/dist/components/otp-field/otp-field.js.map +1 -1
- package/dist/components/pagination/pagination.js +1 -0
- package/dist/components/pagination/pagination.js.map +1 -1
- package/dist/components/popover/popover.js +2 -1
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/preview-card/preview-card.js +2 -1
- package/dist/components/preview-card/preview-card.js.map +1 -1
- package/dist/components/progress/progress.js +1 -0
- package/dist/components/progress/progress.js.map +1 -1
- package/dist/components/radio/radio.js +1 -0
- package/dist/components/radio/radio.js.map +1 -1
- package/dist/components/radio-group/radio-group.js +1 -0
- package/dist/components/radio-group/radio-group.js.map +1 -1
- package/dist/components/rating/rating.js +1 -0
- package/dist/components/rating/rating.js.map +1 -1
- package/dist/components/scroll-area/scroll-area.js +1 -0
- package/dist/components/scroll-area/scroll-area.js.map +1 -1
- package/dist/components/select/select.js +3 -2
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/separator/separator.js +1 -0
- package/dist/components/separator/separator.js.map +1 -1
- package/dist/components/skeleton/skeleton.js +1 -0
- package/dist/components/skeleton/skeleton.js.map +1 -1
- package/dist/components/slider/slider.d.ts.map +1 -1
- package/dist/components/slider/slider.js +3 -1
- package/dist/components/slider/slider.js.map +1 -1
- package/dist/components/sparkline/sparkline.d.ts.map +1 -1
- package/dist/components/sparkline/sparkline.js +2 -0
- package/dist/components/sparkline/sparkline.js.map +1 -1
- package/dist/components/spinner/spinner.js +1 -0
- package/dist/components/spinner/spinner.js.map +1 -1
- package/dist/components/switch/switch.d.ts +15 -15
- package/dist/components/switch/switch.d.ts.map +1 -1
- package/dist/components/switch/switch.js +1 -0
- package/dist/components/switch/switch.js.map +1 -1
- package/dist/components/table/table.js +1 -0
- package/dist/components/table/table.js.map +1 -1
- package/dist/components/tabs/tabs.d.ts +1 -1
- package/dist/components/tabs/tabs.js +2 -1
- package/dist/components/tabs/tabs.js.map +1 -1
- package/dist/components/text-animate/text-animate.js +1 -0
- package/dist/components/text-animate/text-animate.js.map +1 -1
- package/dist/components/textarea/textarea.js +1 -0
- package/dist/components/textarea/textarea.js.map +1 -1
- package/dist/components/thumbnail/thumbnail.d.ts +8 -3
- package/dist/components/thumbnail/thumbnail.d.ts.map +1 -1
- package/dist/components/thumbnail/thumbnail.js +3 -0
- package/dist/components/thumbnail/thumbnail.js.map +1 -1
- package/dist/components/time-field/time-field.js +1 -0
- package/dist/components/time-field/time-field.js.map +1 -1
- package/dist/components/toast/toast.js +1 -0
- package/dist/components/toast/toast.js.map +1 -1
- package/dist/components/toc/toc.js +1 -0
- package/dist/components/toc/toc.js.map +1 -1
- package/dist/components/toggle/toggle.js +1 -0
- package/dist/components/toggle/toggle.js.map +1 -1
- package/dist/components/toggle-group/toggle-group.js +1 -0
- package/dist/components/toggle-group/toggle-group.js.map +1 -1
- package/dist/components/toolbar/toolbar.js +1 -0
- package/dist/components/toolbar/toolbar.js.map +1 -1
- package/dist/components/tooltip/tooltip.js +2 -1
- package/dist/components/tooltip/tooltip.js.map +1 -1
- package/dist/hooks/use-direction.js +1 -0
- package/dist/hooks/use-direction.js.map +1 -1
- package/dist/hooks/use-dismissible.js +1 -0
- package/dist/hooks/use-dismissible.js.map +1 -1
- package/dist/hooks/use-local-storage.js +1 -0
- package/dist/hooks/use-local-storage.js.map +1 -1
- package/dist/hooks/use-media-query.d.ts +0 -4
- package/dist/hooks/use-media-query.d.ts.map +1 -1
- package/dist/hooks/use-media-query.js +1 -0
- package/dist/hooks/use-media-query.js.map +1 -1
- package/dist/hooks/use-reduced-motion.js +1 -0
- package/dist/hooks/use-reduced-motion.js.map +1 -1
- package/dist/hooks/use-theme.js +1 -0
- package/dist/hooks/use-theme.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/color-control.d.ts +9 -9
- package/dist/internal/color-control.d.ts.map +1 -1
- package/dist/internal/color-control.js +1 -0
- package/dist/internal/color-control.js.map +1 -1
- package/dist/internal/color-math.js +1 -0
- package/dist/internal/color-math.js.map +1 -1
- package/dist/internal/color-picker-context.js +1 -0
- package/dist/internal/color-picker-context.js.map +1 -1
- package/dist/internal/floating.d.ts +2 -2
- package/dist/internal/floating.d.ts.map +1 -1
- package/dist/internal/floating.js +1 -0
- package/dist/internal/floating.js.map +1 -1
- package/dist/internal/modal.d.ts +1 -1
- package/dist/internal/modal.d.ts.map +1 -1
- package/dist/internal/modal.js +1 -0
- package/dist/internal/modal.js.map +1 -1
- package/dist/internal/utils.d.ts +2 -2
- package/dist/internal/utils.d.ts.map +1 -1
- package/dist/internal/utils.js +3 -1
- package/dist/internal/utils.js.map +1 -1
- package/dist/lib/color.js +1 -0
- package/dist/lib/color.js.map +1 -1
- package/dist/providers/direction-provider.js +1 -0
- package/dist/providers/direction-provider.js.map +1 -1
- package/dist/providers/reduced-motion-provider.js +1 -0
- package/dist/providers/reduced-motion-provider.js.map +1 -1
- package/dist/providers/theme-provider/index.js +1 -0
- package/dist/providers/theme-provider/index.js.map +1 -1
- package/dist/providers/theme-provider/theme-provider.js +1 -0
- package/dist/providers/theme-provider/theme-provider.js.map +1 -1
- package/dist/providers/theme-provider/theme-script.js +1 -0
- package/dist/providers/theme-provider/theme-script.js.map +1 -1
- package/package.json +36 -29
- package/src/components/alert-dialog/alert-dialog.tsx +1 -1
- package/src/components/autocomplete/autocomplete.tsx +2 -2
- package/src/components/background-pattern/background-pattern-interactive.tsx +3 -1
- package/src/components/background-pattern/background-pattern-shared.tsx +55 -18
- package/src/components/background-pattern/background-pattern.test.tsx +35 -0
- package/src/components/background-pattern/background-pattern.tsx +11 -4
- package/src/components/badge/badge.tsx +1 -1
- package/src/components/breadcrumb/breadcrumb.tsx +1 -1
- package/src/components/button/button-variants.ts +1 -1
- package/src/components/calendar/calendar.tsx +1 -1
- package/src/components/card/card.tsx +1 -1
- package/src/components/carousel/carousel.test.tsx +38 -0
- package/src/components/carousel/carousel.tsx +28 -12
- package/src/components/color-area/color-area.test.tsx +5 -0
- package/src/components/color-area/color-area.tsx +1 -0
- package/src/components/color-slider/color-slider.test.tsx +5 -0
- package/src/components/color-slider/color-slider.tsx +1 -0
- package/src/components/color-swatch-picker/color-swatch-picker.tsx +1 -1
- package/src/components/combobox/combobox.test.tsx +33 -0
- package/src/components/combobox/combobox.tsx +13 -6
- package/src/components/compare-slider/compare-slider.test.tsx +261 -0
- package/src/components/compare-slider/compare-slider.tsx +397 -0
- package/src/components/context-menu/context-menu.test.tsx +28 -0
- package/src/components/context-menu/context-menu.tsx +6 -1
- package/src/components/copy-button/copy-button.test.tsx +13 -0
- package/src/components/copy-button/copy-button.tsx +11 -5
- package/src/components/dialog/dialog.tsx +1 -1
- package/src/components/dropdown-menu/dropdown-menu.test.tsx +216 -0
- package/src/components/dropdown-menu/dropdown-menu.tsx +134 -3
- package/src/components/gradient-glow/gradient-glow.test.tsx +6 -0
- package/src/components/gradient-glow/gradient-glow.tsx +18 -10
- package/src/components/navigation/navigation-link-variants.ts +1 -1
- package/src/components/navigation-menu/navigation-menu.tsx +2 -2
- package/src/components/popover/popover.tsx +1 -1
- package/src/components/preview-card/preview-card.tsx +1 -1
- package/src/components/select/select.tsx +2 -2
- package/src/components/slider/slider.test.tsx +5 -0
- package/src/components/slider/slider.tsx +2 -1
- package/src/components/sparkline/sparkline.test.tsx +16 -0
- package/src/components/sparkline/sparkline.tsx +1 -0
- package/src/components/tabs/tabs.tsx +1 -1
- package/src/components/thumbnail/thumbnail.test.tsx +8 -0
- package/src/components/thumbnail/thumbnail.tsx +7 -0
- package/src/components/tooltip/tooltip.tsx +1 -1
- package/src/hooks/use-media-query.ts +0 -4
- package/src/index.ts +1 -0
- package/src/internal/utils.test.tsx +8 -1
- package/src/internal/utils.ts +4 -1
- package/styles.css +4 -0
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { useDirection } from '../../hooks/use-direction'
|
|
5
|
+
import { cn } from '../../internal/utils'
|
|
6
|
+
|
|
7
|
+
type CompareSliderOrientation = 'horizontal' | 'vertical'
|
|
8
|
+
type CompareSliderLabelPosition = 'top' | 'bottom'
|
|
9
|
+
type LabelCorner = `${CompareSliderLabelPosition}-${'start' | 'end'}`
|
|
10
|
+
|
|
11
|
+
/** How far a touch travels before it counts as a drag rather than a scroll, in pixels. */
|
|
12
|
+
const DRAG_THRESHOLD = 6
|
|
13
|
+
const STEP = 1
|
|
14
|
+
const PAGE_STEP = 10
|
|
15
|
+
|
|
16
|
+
const ROOT_ORIENTATION: Record<CompareSliderOrientation, string> = {
|
|
17
|
+
horizontal: 'cursor-ew-resize touch-pan-y',
|
|
18
|
+
vertical: 'cursor-ns-resize touch-pan-x',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const DIVIDER_ORIENTATION: Record<CompareSliderOrientation, string> = {
|
|
22
|
+
horizontal: 'inset-y-0 w-0.5 ltr:-translate-x-1/2 rtl:translate-x-1/2',
|
|
23
|
+
vertical: 'inset-x-0 h-0.5 -translate-y-1/2',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const HANDLE_ORIENTATION: Record<CompareSliderOrientation, string> = {
|
|
27
|
+
horizontal: 'top-1/2 -translate-y-1/2 ltr:-translate-x-1/2 rtl:translate-x-1/2',
|
|
28
|
+
vertical: 'inset-s-1/2 -translate-y-1/2 ltr:-translate-x-1/2 rtl:translate-x-1/2',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const POSITION_TRANSITION: Record<CompareSliderOrientation, string> = {
|
|
32
|
+
horizontal: 'transition-[inset-inline-start]',
|
|
33
|
+
vertical: 'transition-[top]',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const REVEAL_TIMING = 'duration-1000 ease-out motion-reduce:transition-none'
|
|
37
|
+
|
|
38
|
+
const PRESS_TIMING =
|
|
39
|
+
'transition duration-250 ease-spring group-data-dragging/compare-slider:duration-100 group-data-dragging/compare-slider:ease-in-out motion-reduce:transition-none'
|
|
40
|
+
|
|
41
|
+
const LAYER_CLASSES = 'relative col-start-1 row-start-1 min-h-0 min-w-0 [&>img]:size-full [&>img]:object-cover'
|
|
42
|
+
|
|
43
|
+
const LABEL_CLASSES =
|
|
44
|
+
'border-border bg-background text-foreground-intense absolute flex h-7 items-center rounded-full border px-3 text-sm whitespace-nowrap'
|
|
45
|
+
|
|
46
|
+
const LABEL_CORNER: Record<LabelCorner, string> = {
|
|
47
|
+
'top-start': 'top-3 inset-s-3',
|
|
48
|
+
'top-end': 'top-3 inset-e-3',
|
|
49
|
+
'bottom-start': 'bottom-3 inset-s-3',
|
|
50
|
+
'bottom-end': 'bottom-3 inset-e-3',
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface CompareSliderProps extends Omit<
|
|
54
|
+
React.ComponentPropsWithoutRef<'div'>,
|
|
55
|
+
'children' | 'defaultValue' | 'onChange'
|
|
56
|
+
> {
|
|
57
|
+
/** Layer on the start side of the divider, or above it when vertical. */
|
|
58
|
+
before: React.ReactNode
|
|
59
|
+
/** Layer on the end side of the divider, or below it when vertical. */
|
|
60
|
+
after: React.ReactNode
|
|
61
|
+
/** Divider position as a percentage of the way from the start edge (the top when vertical). Pass it to control the component. */
|
|
62
|
+
value?: number
|
|
63
|
+
/**
|
|
64
|
+
* Divider position on first render, as a percentage of the way from the start edge, when the component is uncontrolled.
|
|
65
|
+
* @default 50
|
|
66
|
+
*/
|
|
67
|
+
defaultValue?: number
|
|
68
|
+
/** Fires on every change, including each frame of a drag. */
|
|
69
|
+
onValueChange?: (value: number) => void
|
|
70
|
+
/** Fires once a drag ends or a key press settles, with the position landed on. */
|
|
71
|
+
onValueCommitted?: (value: number) => void
|
|
72
|
+
/**
|
|
73
|
+
* Axis the divider travels along. Vertical stacks `before` above `after`.
|
|
74
|
+
* @default 'horizontal'
|
|
75
|
+
*/
|
|
76
|
+
orientation?: CompareSliderOrientation
|
|
77
|
+
/** Caption in a corner of the `before` layer, clipped with it as the divider passes. */
|
|
78
|
+
beforeLabel?: React.ReactNode
|
|
79
|
+
/** Caption in a corner of the `after` layer, clipped with it as the divider passes. */
|
|
80
|
+
afterLabel?: React.ReactNode
|
|
81
|
+
/**
|
|
82
|
+
* Edge the labels sit along. A vertical slider ignores it and puts each label at its own end.
|
|
83
|
+
* @default 'bottom'
|
|
84
|
+
*/
|
|
85
|
+
labelPosition?: CompareSliderLabelPosition
|
|
86
|
+
/** Icon on the handle. Defaults to a double arrow that follows `orientation`. */
|
|
87
|
+
icon?: React.ReactNode
|
|
88
|
+
/**
|
|
89
|
+
* Open on `before` alone and wipe the divider in to `defaultValue` the first time the slider scrolls into view. Uncontrolled only.
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
reveal?: boolean
|
|
93
|
+
/**
|
|
94
|
+
* Prevent moving the divider.
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
disabled?: boolean
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function clamp(value: number): number {
|
|
101
|
+
return Math.min(100, Math.max(0, value))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Clips each layer to its side of the divider, so a transparent layer never shows the other through it. */
|
|
105
|
+
function layerClips(position: number, vertical: boolean, rtl: boolean): [before: string, after: string] {
|
|
106
|
+
const rest = 100 - position
|
|
107
|
+
if (vertical) return [`inset(0 0 ${rest}% 0)`, `inset(${position}% 0 0 0)`]
|
|
108
|
+
return rtl
|
|
109
|
+
? [`inset(0 0 0 ${rest}%)`, `inset(0 ${position}% 0 0)`]
|
|
110
|
+
: [`inset(0 ${rest}% 0 0)`, `inset(0 0 0 ${position}%)`]
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function CompareSlider({
|
|
114
|
+
before,
|
|
115
|
+
after,
|
|
116
|
+
value,
|
|
117
|
+
defaultValue = 50,
|
|
118
|
+
onValueChange,
|
|
119
|
+
onValueCommitted,
|
|
120
|
+
orientation = 'horizontal',
|
|
121
|
+
beforeLabel,
|
|
122
|
+
afterLabel,
|
|
123
|
+
labelPosition = 'bottom',
|
|
124
|
+
icon,
|
|
125
|
+
reveal = false,
|
|
126
|
+
disabled = false,
|
|
127
|
+
className,
|
|
128
|
+
'aria-label': ariaLabel,
|
|
129
|
+
'aria-labelledby': ariaLabelledBy,
|
|
130
|
+
...props
|
|
131
|
+
}: CompareSliderProps) {
|
|
132
|
+
const rtl = useDirection() === 'rtl'
|
|
133
|
+
const vertical = orientation === 'vertical'
|
|
134
|
+
const controlled = value !== undefined
|
|
135
|
+
|
|
136
|
+
const rootRef = React.useRef<HTMLDivElement>(null)
|
|
137
|
+
const inputRef = React.useRef<HTMLInputElement>(null)
|
|
138
|
+
const gestureRef = React.useRef<{ x: number; y: number; tracking: boolean } | null>(null)
|
|
139
|
+
|
|
140
|
+
const [uncontrolled, setUncontrolled] = React.useState(() => clamp(defaultValue))
|
|
141
|
+
const [seen, setSeen] = React.useState(!reveal)
|
|
142
|
+
const [touched, setTouched] = React.useState(false)
|
|
143
|
+
const [dragging, setDragging] = React.useState(false)
|
|
144
|
+
|
|
145
|
+
const position = controlled ? clamp(value) : reveal && !seen && !touched ? 100 : uncontrolled
|
|
146
|
+
const revealing = reveal && !controlled && !touched
|
|
147
|
+
|
|
148
|
+
const latestRef = React.useRef(position)
|
|
149
|
+
latestRef.current = position
|
|
150
|
+
|
|
151
|
+
React.useEffect(() => {
|
|
152
|
+
if (!reveal || seen) return
|
|
153
|
+
const node = rootRef.current
|
|
154
|
+
if (!node || typeof IntersectionObserver === 'undefined') {
|
|
155
|
+
setSeen(true)
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
const observer = new IntersectionObserver(
|
|
159
|
+
([entry]) => {
|
|
160
|
+
if (entry?.isIntersecting) setSeen(true)
|
|
161
|
+
},
|
|
162
|
+
{ threshold: 0.4 },
|
|
163
|
+
)
|
|
164
|
+
observer.observe(node)
|
|
165
|
+
return () => observer.disconnect()
|
|
166
|
+
}, [reveal, seen])
|
|
167
|
+
|
|
168
|
+
const update = (next: number) => {
|
|
169
|
+
const clamped = clamp(next)
|
|
170
|
+
setTouched(true)
|
|
171
|
+
if (clamped === latestRef.current) return
|
|
172
|
+
latestRef.current = clamped
|
|
173
|
+
if (!controlled) setUncontrolled(clamped)
|
|
174
|
+
onValueChange?.(clamped)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const placeAt = (clientX: number, clientY: number) => {
|
|
178
|
+
const rect = rootRef.current?.getBoundingClientRect()
|
|
179
|
+
if (!rect?.width || !rect.height) return
|
|
180
|
+
const ratio = vertical ? (clientY - rect.top) / rect.height : (clientX - rect.left) / rect.width
|
|
181
|
+
update((!vertical && rtl ? 1 - ratio : ratio) * 100)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const capture = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
185
|
+
try {
|
|
186
|
+
// Capture last: it throws when the pointer is already gone, by which point the
|
|
187
|
+
// press has been applied and a failure only costs tracking outside the element.
|
|
188
|
+
event.currentTarget.setPointerCapture(event.pointerId)
|
|
189
|
+
} catch {}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const handlePointerDown = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
193
|
+
if (disabled || (event.pointerType === 'mouse' && event.button !== 0)) return
|
|
194
|
+
const mouse = event.pointerType === 'mouse'
|
|
195
|
+
gestureRef.current = { x: event.clientX, y: event.clientY, tracking: mouse }
|
|
196
|
+
setDragging(true)
|
|
197
|
+
if (!mouse) return
|
|
198
|
+
placeAt(event.clientX, event.clientY)
|
|
199
|
+
inputRef.current?.focus({ preventScroll: true })
|
|
200
|
+
capture(event)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const handlePointerMove = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
204
|
+
const gesture = gestureRef.current
|
|
205
|
+
if (!gesture) return
|
|
206
|
+
if (!gesture.tracking) {
|
|
207
|
+
const dx = Math.abs(event.clientX - gesture.x)
|
|
208
|
+
const dy = Math.abs(event.clientY - gesture.y)
|
|
209
|
+
if (dx < DRAG_THRESHOLD && dy < DRAG_THRESHOLD) return
|
|
210
|
+
if (vertical ? dx > dy : dy > dx) {
|
|
211
|
+
gestureRef.current = null
|
|
212
|
+
setDragging(false)
|
|
213
|
+
return
|
|
214
|
+
}
|
|
215
|
+
gesture.tracking = true
|
|
216
|
+
capture(event)
|
|
217
|
+
}
|
|
218
|
+
placeAt(event.clientX, event.clientY)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const endDrag = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
222
|
+
const gesture = gestureRef.current
|
|
223
|
+
gestureRef.current = null
|
|
224
|
+
if (!gesture) return
|
|
225
|
+
setDragging(false)
|
|
226
|
+
if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {
|
|
227
|
+
event.currentTarget.releasePointerCapture(event.pointerId)
|
|
228
|
+
}
|
|
229
|
+
if (!gesture.tracking) {
|
|
230
|
+
if (event.type !== 'pointerup') return
|
|
231
|
+
placeAt(event.clientX, event.clientY)
|
|
232
|
+
inputRef.current?.focus({ preventScroll: true })
|
|
233
|
+
}
|
|
234
|
+
onValueCommitted?.(latestRef.current)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
238
|
+
if (disabled) return
|
|
239
|
+
const step = event.shiftKey ? PAGE_STEP : STEP
|
|
240
|
+
const across = !vertical && rtl ? -1 : 1
|
|
241
|
+
const deltas: Record<string, number | undefined> = {
|
|
242
|
+
ArrowLeft: -across * step,
|
|
243
|
+
ArrowRight: across * step,
|
|
244
|
+
ArrowUp: vertical ? -step : step,
|
|
245
|
+
ArrowDown: vertical ? step : -step,
|
|
246
|
+
PageUp: vertical ? -PAGE_STEP : PAGE_STEP,
|
|
247
|
+
PageDown: vertical ? PAGE_STEP : -PAGE_STEP,
|
|
248
|
+
}
|
|
249
|
+
const next =
|
|
250
|
+
event.key === 'Home' ? 0 : event.key === 'End' ? 100 : latestRef.current + (deltas[event.key] ?? Number.NaN)
|
|
251
|
+
if (Number.isNaN(next)) return
|
|
252
|
+
event.preventDefault()
|
|
253
|
+
update(next)
|
|
254
|
+
onValueCommitted?.(latestRef.current)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const [beforeClip, afterClip] = layerClips(position, vertical, rtl)
|
|
258
|
+
const offset = { [vertical ? 'top' : 'insetInlineStart']: `${position}%` }
|
|
259
|
+
const positionTransition = revealing && cn(POSITION_TRANSITION[orientation], REVEAL_TIMING)
|
|
260
|
+
const clipTransition = revealing && `transition-[clip-path] ${REVEAL_TIMING}`
|
|
261
|
+
const beforeCorner: LabelCorner = vertical ? 'top-start' : `${labelPosition}-start`
|
|
262
|
+
const afterCorner: LabelCorner = vertical ? 'bottom-start' : `${labelPosition}-end`
|
|
263
|
+
|
|
264
|
+
return (
|
|
265
|
+
<div
|
|
266
|
+
ref={rootRef}
|
|
267
|
+
data-base-ui-swipe-ignore={vertical ? 'y' : 'x'}
|
|
268
|
+
{...props}
|
|
269
|
+
data-slot="compare-slider"
|
|
270
|
+
data-orientation={orientation}
|
|
271
|
+
data-dragging={dragging ? '' : undefined}
|
|
272
|
+
data-disabled={disabled ? '' : undefined}
|
|
273
|
+
className={cn(
|
|
274
|
+
'group/compare-slider relative isolate rounded-2xl select-none',
|
|
275
|
+
disabled ? 'cursor-default' : ROOT_ORIENTATION[orientation],
|
|
276
|
+
className,
|
|
277
|
+
)}
|
|
278
|
+
onPointerDown={handlePointerDown}
|
|
279
|
+
onPointerMove={handlePointerMove}
|
|
280
|
+
onPointerUp={endDrag}
|
|
281
|
+
onPointerCancel={endDrag}
|
|
282
|
+
>
|
|
283
|
+
<div
|
|
284
|
+
data-slot="compare-slider-viewport"
|
|
285
|
+
className="bg-background-muted pointer-events-none grid size-full overflow-hidden rounded-[inherit]"
|
|
286
|
+
>
|
|
287
|
+
<div
|
|
288
|
+
data-slot="compare-slider-before"
|
|
289
|
+
className={cn(LAYER_CLASSES, clipTransition)}
|
|
290
|
+
style={{ clipPath: beforeClip }}
|
|
291
|
+
>
|
|
292
|
+
{before}
|
|
293
|
+
{beforeLabel ? (
|
|
294
|
+
<span data-slot="compare-slider-label" className={cn(LABEL_CLASSES, LABEL_CORNER[beforeCorner])}>
|
|
295
|
+
{beforeLabel}
|
|
296
|
+
</span>
|
|
297
|
+
) : null}
|
|
298
|
+
</div>
|
|
299
|
+
<div
|
|
300
|
+
data-slot="compare-slider-after"
|
|
301
|
+
className={cn(LAYER_CLASSES, clipTransition)}
|
|
302
|
+
style={{ clipPath: afterClip }}
|
|
303
|
+
>
|
|
304
|
+
{after}
|
|
305
|
+
{afterLabel ? (
|
|
306
|
+
<span data-slot="compare-slider-label" className={cn(LABEL_CLASSES, LABEL_CORNER[afterCorner])}>
|
|
307
|
+
{afterLabel}
|
|
308
|
+
</span>
|
|
309
|
+
) : null}
|
|
310
|
+
</div>
|
|
311
|
+
<div
|
|
312
|
+
data-slot="compare-slider-divider"
|
|
313
|
+
aria-hidden="true"
|
|
314
|
+
className={cn(
|
|
315
|
+
'light absolute bg-white shadow-md shadow-black/20',
|
|
316
|
+
DIVIDER_ORIENTATION[orientation],
|
|
317
|
+
positionTransition,
|
|
318
|
+
)}
|
|
319
|
+
style={offset}
|
|
320
|
+
/>
|
|
321
|
+
</div>
|
|
322
|
+
|
|
323
|
+
<input
|
|
324
|
+
ref={inputRef}
|
|
325
|
+
type="range"
|
|
326
|
+
className="sr-only"
|
|
327
|
+
min={0}
|
|
328
|
+
max={100}
|
|
329
|
+
value={Math.round(position)}
|
|
330
|
+
disabled={disabled}
|
|
331
|
+
aria-label={ariaLabelledBy ? undefined : (ariaLabel ?? 'Divider position')}
|
|
332
|
+
aria-labelledby={ariaLabelledBy}
|
|
333
|
+
aria-orientation={orientation}
|
|
334
|
+
onKeyDown={handleKeyDown}
|
|
335
|
+
onChange={(event) => update(Number(event.target.value))}
|
|
336
|
+
/>
|
|
337
|
+
|
|
338
|
+
<span
|
|
339
|
+
data-slot="compare-slider-handle"
|
|
340
|
+
aria-hidden="true"
|
|
341
|
+
className={cn(
|
|
342
|
+
'light bg-background text-foreground-intense outline-ring pointer-events-none absolute grid size-11 place-items-center rounded-full shadow-lg shadow-black/25',
|
|
343
|
+
"[&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-5",
|
|
344
|
+
'group-has-focus-visible/compare-slider:outline-2 group-has-focus-visible/compare-slider:outline-offset-2',
|
|
345
|
+
'group-data-disabled/compare-slider:bg-background/60 group-data-disabled/compare-slider:*:opacity-disabled group-data-disabled/compare-slider:shadow-none group-data-disabled/compare-slider:backdrop-blur-md',
|
|
346
|
+
'transform-gpu group-data-dragging/compare-slider:translate-y-[calc(-50%+1px)] group-data-dragging/compare-slider:scale-[0.97]',
|
|
347
|
+
HANDLE_ORIENTATION[orientation],
|
|
348
|
+
revealing ? positionTransition : PRESS_TIMING,
|
|
349
|
+
)}
|
|
350
|
+
style={offset}
|
|
351
|
+
>
|
|
352
|
+
{icon ?? (vertical ? <ArrowsVerticalIcon /> : <ArrowsHorizontalIcon />)}
|
|
353
|
+
</span>
|
|
354
|
+
</div>
|
|
355
|
+
)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
interface IconProps extends React.SVGProps<SVGSVGElement> {}
|
|
359
|
+
|
|
360
|
+
function ArrowsHorizontalIcon(props: IconProps) {
|
|
361
|
+
return (
|
|
362
|
+
<svg
|
|
363
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
364
|
+
viewBox="0 0 24 24"
|
|
365
|
+
fill="none"
|
|
366
|
+
stroke="currentColor"
|
|
367
|
+
strokeWidth="1.5"
|
|
368
|
+
strokeLinecap="round"
|
|
369
|
+
strokeLinejoin="round"
|
|
370
|
+
aria-hidden="true"
|
|
371
|
+
{...props}
|
|
372
|
+
>
|
|
373
|
+
<path d="m7 8-4 4m0 0 4 4m-4-4h18m-4-4 4 4m0 0-4 4" />
|
|
374
|
+
</svg>
|
|
375
|
+
)
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function ArrowsVerticalIcon(props: IconProps) {
|
|
379
|
+
return (
|
|
380
|
+
<svg
|
|
381
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
382
|
+
viewBox="0 0 24 24"
|
|
383
|
+
fill="none"
|
|
384
|
+
stroke="currentColor"
|
|
385
|
+
strokeWidth="1.5"
|
|
386
|
+
strokeLinecap="round"
|
|
387
|
+
strokeLinejoin="round"
|
|
388
|
+
aria-hidden="true"
|
|
389
|
+
{...props}
|
|
390
|
+
>
|
|
391
|
+
<path d="m8 7 4-4m0 0 4 4m-4-4v18m-4-4 4 4m0 0 4-4" />
|
|
392
|
+
</svg>
|
|
393
|
+
)
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export { CompareSlider }
|
|
397
|
+
export type { CompareSliderProps }
|
|
@@ -86,6 +86,34 @@ describe('ContextMenu', () => {
|
|
|
86
86
|
expect(item.className).toContain('text-base')
|
|
87
87
|
})
|
|
88
88
|
|
|
89
|
+
it('marks every item kind with data-orientation="vertical"', async () => {
|
|
90
|
+
const user = setupUser()
|
|
91
|
+
render(
|
|
92
|
+
<ContextMenu>
|
|
93
|
+
<ContextMenuTrigger data-testid="trigger">Right click here</ContextMenuTrigger>
|
|
94
|
+
<ContextMenuContent>
|
|
95
|
+
<ContextMenuItem>Item</ContextMenuItem>
|
|
96
|
+
<ContextMenuLinkItem href="https://example.com">Link</ContextMenuLinkItem>
|
|
97
|
+
<ContextMenuCheckboxItem>Check</ContextMenuCheckboxItem>
|
|
98
|
+
<ContextMenuRadioGroup value="a">
|
|
99
|
+
<ContextMenuRadioItem value="a">Radio</ContextMenuRadioItem>
|
|
100
|
+
</ContextMenuRadioGroup>
|
|
101
|
+
<ContextMenuSub>
|
|
102
|
+
<ContextMenuSubTrigger>More</ContextMenuSubTrigger>
|
|
103
|
+
<ContextMenuSubContent>
|
|
104
|
+
<ContextMenuItem>Nested</ContextMenuItem>
|
|
105
|
+
</ContextMenuSubContent>
|
|
106
|
+
</ContextMenuSub>
|
|
107
|
+
</ContextMenuContent>
|
|
108
|
+
</ContextMenu>,
|
|
109
|
+
)
|
|
110
|
+
await user.pointer({ keys: '[MouseRight]', target: screen.getByTestId('trigger') })
|
|
111
|
+
await screen.findByRole('menuitem', { name: 'Item' })
|
|
112
|
+
const items = document.querySelectorAll('[data-slot$="-item"], [data-slot="context-menu-sub-trigger"]')
|
|
113
|
+
expect(items).toHaveLength(5)
|
|
114
|
+
items.forEach((item) => expect(item).toHaveAttribute('data-orientation', 'vertical'))
|
|
115
|
+
})
|
|
116
|
+
|
|
89
117
|
it('renders the popup with size-driven radius', async () => {
|
|
90
118
|
const user = setupUser()
|
|
91
119
|
render(<BasicMenu size="sm" />)
|
|
@@ -67,7 +67,7 @@ function popupClassName(size: ContextMenuSize, className?: string) {
|
|
|
67
67
|
'max-h-(--available-height) bg-background border-border-overlay flex flex-col border shadow-2xl outline-none',
|
|
68
68
|
POPUP_SIZE[size],
|
|
69
69
|
'origin-(--transform-origin)',
|
|
70
|
-
'motion-safe:transition-[opacity,scale] motion-safe:duration-200 motion-safe:ease-
|
|
70
|
+
'motion-safe:transition-[opacity,scale] motion-safe:duration-200 motion-safe:ease-spring',
|
|
71
71
|
'data-starting-style:motion-safe:scale-90 data-starting-style:motion-safe:opacity-0',
|
|
72
72
|
'data-ending-style:motion-safe:scale-95 data-ending-style:motion-safe:opacity-0 data-ending-style:motion-safe:duration-100 data-ending-style:motion-safe:ease-out',
|
|
73
73
|
className,
|
|
@@ -119,6 +119,7 @@ function ContextMenuItem({ className, ...props }: ContextMenuItemProps) {
|
|
|
119
119
|
return (
|
|
120
120
|
<BaseContextMenu.Item
|
|
121
121
|
data-slot="context-menu-item"
|
|
122
|
+
data-orientation="vertical"
|
|
122
123
|
className={cn(navigationLinkVariants({ variant: 'pill', size }), ITEM_BASE, className)}
|
|
123
124
|
{...props}
|
|
124
125
|
/>
|
|
@@ -132,6 +133,7 @@ function ContextMenuLinkItem({ className, ...props }: ContextMenuLinkItemProps)
|
|
|
132
133
|
return (
|
|
133
134
|
<BaseContextMenu.LinkItem
|
|
134
135
|
data-slot="context-menu-link-item"
|
|
136
|
+
data-orientation="vertical"
|
|
135
137
|
className={cn(navigationLinkVariants({ variant: 'pill', size }), ITEM_BASE, className)}
|
|
136
138
|
{...props}
|
|
137
139
|
/>
|
|
@@ -188,6 +190,7 @@ function ContextMenuRadioItem({ className, children, ...props }: ContextMenuRadi
|
|
|
188
190
|
return (
|
|
189
191
|
<BaseContextMenu.RadioItem
|
|
190
192
|
data-slot="context-menu-radio-item"
|
|
193
|
+
data-orientation="vertical"
|
|
191
194
|
className={cn(navigationLinkVariants({ variant: 'pill', size }), ITEM_BASE, 'justify-between', className)}
|
|
192
195
|
{...props}
|
|
193
196
|
>
|
|
@@ -210,6 +213,7 @@ function ContextMenuCheckboxItem({ className, children, ...props }: ContextMenuC
|
|
|
210
213
|
return (
|
|
211
214
|
<BaseContextMenu.CheckboxItem
|
|
212
215
|
data-slot="context-menu-checkbox-item"
|
|
216
|
+
data-orientation="vertical"
|
|
213
217
|
className={cn(navigationLinkVariants({ variant: 'pill', size }), ITEM_BASE, 'justify-between', className)}
|
|
214
218
|
{...props}
|
|
215
219
|
>
|
|
@@ -239,6 +243,7 @@ function ContextMenuSubTrigger({ className, children, ...props }: ContextMenuSub
|
|
|
239
243
|
<BaseContextMenu.SubmenuTrigger className="group/submenu-trigger outline-hidden" {...props}>
|
|
240
244
|
<span
|
|
241
245
|
data-slot="context-menu-sub-trigger"
|
|
246
|
+
data-orientation="vertical"
|
|
242
247
|
className={cn(navigationLinkVariants({ variant: 'pill', size }), ITEM_BASE, 'justify-between', className)}
|
|
243
248
|
>
|
|
244
249
|
<span className={cn('flex flex-1 items-center', ITEM_TEXT[size])}>{children}</span>
|
|
@@ -39,6 +39,19 @@ describe('CopyButton', () => {
|
|
|
39
39
|
expect(screen.getAllByText('Copied').length).toBeGreaterThanOrEqual(1)
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
+
it('renders a custom resting icon in place of the copy glyph and still swaps to the check', async () => {
|
|
43
|
+
const { user } = setup()
|
|
44
|
+
render(<CopyButton value="hello" icon={<svg data-testid="link-icon" />} />)
|
|
45
|
+
const button = screen.getByRole('button', { name: 'Copy' })
|
|
46
|
+
expect(screen.getByTestId('link-icon')).toBeInTheDocument()
|
|
47
|
+
expect(button.querySelectorAll('svg')).toHaveLength(2)
|
|
48
|
+
|
|
49
|
+
await user.click(button)
|
|
50
|
+
|
|
51
|
+
await waitFor(() => expect(button).toHaveAttribute('data-copied'))
|
|
52
|
+
expect(screen.getByTestId('link-icon')).toBeInTheDocument()
|
|
53
|
+
})
|
|
54
|
+
|
|
42
55
|
it('copies the string value on click', async () => {
|
|
43
56
|
const { user, writeText } = setup()
|
|
44
57
|
const onCopy = vi.fn()
|
|
@@ -69,6 +69,8 @@ interface CopyButtonProps extends Omit<ButtonProps, 'value' | 'onCopy'> {
|
|
|
69
69
|
onCopy?: (value: string) => void
|
|
70
70
|
/** Called if reading the value or writing to the clipboard fails. */
|
|
71
71
|
onCopyError?: (error: unknown) => void
|
|
72
|
+
/** Icon shown at rest, cross-faded to the drawn check after a copy. Defaults to a built-in copy glyph. */
|
|
73
|
+
icon?: React.ReactNode
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
function CopyButton({
|
|
@@ -78,6 +80,7 @@ function CopyButton({
|
|
|
78
80
|
copiedLabel = 'Copied',
|
|
79
81
|
onCopy,
|
|
80
82
|
onCopyError,
|
|
83
|
+
icon,
|
|
81
84
|
onClick,
|
|
82
85
|
variant = 'ghost',
|
|
83
86
|
size = 'icon-sm',
|
|
@@ -120,16 +123,19 @@ function CopyButton({
|
|
|
120
123
|
{...props}
|
|
121
124
|
>
|
|
122
125
|
<span data-icon={children != null ? 'start' : undefined} className="grid place-items-center *:[grid-area:1/1]">
|
|
123
|
-
<
|
|
124
|
-
{...ICON_SVG_PROPS}
|
|
126
|
+
<span
|
|
125
127
|
className={cn(
|
|
126
|
-
'transition-[opacity,scale] delay-150 duration-150 ease-out group-data-copied/copy:delay-0',
|
|
128
|
+
'grid place-items-center transition-[opacity,scale] delay-150 duration-150 ease-out group-data-copied/copy:delay-0',
|
|
127
129
|
'group-data-copied/copy:scale-50 group-data-copied/copy:opacity-0',
|
|
128
130
|
'motion-reduce:transition-none',
|
|
129
131
|
)}
|
|
130
132
|
>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
{icon ?? (
|
|
134
|
+
<svg {...ICON_SVG_PROPS}>
|
|
135
|
+
<path d="M4.012 16.737c-.307-.175-.562-.427-.739-.732S3.001 15.353 3 15V5c0-1.1.9-2 2-2h10c.75 0 1.158.385 1.5 1M7 9.667c0-.707.281-1.386.781-1.886S8.96 7 9.667 7h8.666c.35 0 .697.069 1.021.203s.618.33.865.578.444.542.578.865A2.67 2.67 0 0 1 21 9.667v8.666a2.67 2.67 0 0 1-.781 1.886 2.67 2.67 0 0 1-1.886.781H9.667a2.67 2.67 0 0 1-1.021-.203c-.324-.134-.618-.331-.865-.578s-.444-.542-.578-.865S7 18.683 7 18.333V9.667z" />
|
|
136
|
+
</svg>
|
|
137
|
+
)}
|
|
138
|
+
</span>
|
|
133
139
|
<svg {...ICON_SVG_PROPS}>
|
|
134
140
|
<path
|
|
135
141
|
d={CHECK_PATH}
|
|
@@ -94,7 +94,7 @@ function DialogContent({
|
|
|
94
94
|
showFrame ? 'border-white/15 bg-white/10 p-1.5 backdrop-blur-sm' : 'bg-background border-border-overlay',
|
|
95
95
|
!showFrame && 'shadow-2xl',
|
|
96
96
|
'isolate transform-gpu outline-none',
|
|
97
|
-
'motion-safe:transition-[opacity,scale] motion-safe:duration-250
|
|
97
|
+
'motion-safe:ease-spring motion-safe:transition-[opacity,scale] motion-safe:duration-250',
|
|
98
98
|
'data-starting-style:motion-safe:scale-95 data-starting-style:motion-safe:opacity-0',
|
|
99
99
|
'data-ending-style:motion-safe:scale-95 data-ending-style:motion-safe:opacity-0 data-ending-style:motion-safe:duration-100 data-ending-style:motion-safe:ease-out',
|
|
100
100
|
'data-nested-dialog-open:pointer-events-none data-nested-dialog-open:scale-95 data-nested-dialog-open:opacity-0',
|