@slurp-ui/react 1.1.1 → 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 +56 -0
- package/dist/AvatarGroup/AvatarGroup.d.ts +26 -0
- package/dist/AvatarGroup/AvatarGroup.js +46 -0
- package/dist/AvatarGroup/AvatarGroup.js.map +1 -0
- package/dist/AvatarGroup/index.d.ts +3 -0
- package/dist/AvatarGroup/index.js +2 -0
- package/dist/Bloom/Bloom.js +3 -2
- package/dist/Bloom/Bloom.js.map +1 -1
- package/dist/Calendar/Calendar.d.ts +42 -0
- package/dist/Calendar/Calendar.js +178 -0
- package/dist/Calendar/Calendar.js.map +1 -0
- package/dist/Calendar/dates.d.ts +3 -0
- package/dist/Calendar/dates.js +46 -0
- package/dist/Calendar/dates.js.map +1 -0
- package/dist/Calendar/index.d.ts +3 -0
- package/dist/Calendar/index.js +2 -0
- package/dist/Carousel/Carousel.js +2 -0
- package/dist/Carousel/Carousel.js.map +1 -1
- package/dist/Choice/Choice.js +2 -0
- package/dist/Choice/Choice.js.map +1 -1
- package/dist/Code/Code.d.ts +38 -0
- package/dist/Code/Code.js +82 -0
- package/dist/Code/Code.js.map +1 -0
- package/dist/Code/index.d.ts +3 -0
- package/dist/Code/index.js +2 -0
- package/dist/Compare/Compare.d.ts +23 -0
- package/dist/Compare/Compare.js +61 -0
- package/dist/Compare/Compare.js.map +1 -0
- package/dist/Compare/index.d.ts +3 -0
- package/dist/Compare/index.js +2 -0
- package/dist/Consent/Consent.d.ts +30 -0
- package/dist/Consent/Consent.js +70 -0
- package/dist/Consent/Consent.js.map +1 -0
- package/dist/Consent/index.d.ts +3 -0
- package/dist/Consent/index.js +2 -0
- package/dist/Contents/Contents.d.ts +35 -0
- package/dist/Contents/Contents.js +63 -0
- package/dist/Contents/Contents.js.map +1 -0
- package/dist/Contents/index.d.ts +3 -0
- package/dist/Contents/index.js +2 -0
- package/dist/DateField/DateField.d.ts +29 -0
- package/dist/DateField/DateField.js +118 -0
- package/dist/DateField/DateField.js.map +1 -0
- package/dist/DateField/index.d.ts +3 -0
- package/dist/DateField/index.js +2 -0
- package/dist/Dialog/Dialog.d.ts +2 -0
- package/dist/Dialog/Dialog.js +89 -30
- package/dist/Dialog/Dialog.js.map +1 -1
- package/dist/Dock/Dock.d.ts +5 -0
- package/dist/Dock/Dock.js +13 -2
- package/dist/Dock/Dock.js.map +1 -1
- package/dist/ErrorSummary/ErrorSummary.d.ts +26 -0
- package/dist/ErrorSummary/ErrorSummary.js +68 -0
- package/dist/ErrorSummary/ErrorSummary.js.map +1 -0
- package/dist/ErrorSummary/index.d.ts +3 -0
- package/dist/ErrorSummary/index.js +2 -0
- package/dist/FileDrop/FileDrop.d.ts +34 -0
- package/dist/FileDrop/FileDrop.js +145 -0
- package/dist/FileDrop/FileDrop.js.map +1 -0
- package/dist/FileDrop/index.d.ts +3 -0
- package/dist/FileDrop/index.js +2 -0
- package/dist/Filters/Filters.js +2 -0
- package/dist/Filters/Filters.js.map +1 -1
- package/dist/Footer/Footer.d.ts +37 -0
- package/dist/Footer/Footer.js +63 -0
- package/dist/Footer/Footer.js.map +1 -0
- package/dist/Footer/index.d.ts +3 -0
- package/dist/Footer/index.js +2 -0
- package/dist/Hairline/Hairline.d.ts +16 -0
- package/dist/Hairline/Hairline.js +23 -0
- package/dist/Hairline/Hairline.js.map +1 -0
- package/dist/Hairline/index.d.ts +3 -0
- package/dist/Hairline/index.js +2 -0
- package/dist/Hint/Hint.js +20 -1
- package/dist/Hint/Hint.js.map +1 -1
- package/dist/Kbd/Kbd.d.ts +7 -0
- package/dist/Kbd/Kbd.js +20 -0
- package/dist/Kbd/Kbd.js.map +1 -0
- package/dist/Kbd/index.d.ts +3 -0
- package/dist/Kbd/index.js +2 -0
- package/dist/Lightbox/Lightbox.d.ts +30 -0
- package/dist/Lightbox/Lightbox.js +74 -0
- package/dist/Lightbox/Lightbox.js.map +1 -0
- package/dist/Lightbox/index.d.ts +3 -0
- package/dist/Lightbox/index.js +2 -0
- package/dist/ListRow/ListRow.d.ts +5 -1
- package/dist/ListRow/ListRow.js +5 -1
- package/dist/ListRow/ListRow.js.map +1 -1
- package/dist/Media/Media.d.ts +28 -0
- package/dist/Media/Media.js +65 -0
- package/dist/Media/Media.js.map +1 -0
- package/dist/Media/index.d.ts +3 -0
- package/dist/Media/index.js +2 -0
- package/dist/Menu/Menu.d.ts +13 -0
- package/dist/Menu/Menu.js +43 -11
- package/dist/Menu/Menu.js.map +1 -1
- package/dist/Menu/index.d.ts +2 -2
- package/dist/Menu/index.js +1 -1
- package/dist/MultiSuggest/MultiSuggest.d.ts +39 -0
- package/dist/MultiSuggest/MultiSuggest.js +267 -0
- package/dist/MultiSuggest/MultiSuggest.js.map +1 -0
- package/dist/MultiSuggest/index.d.ts +3 -0
- package/dist/MultiSuggest/index.js +2 -0
- package/dist/Notice/Notice.js +2 -0
- package/dist/Notice/Notice.js.map +1 -1
- package/dist/NumberField/NumberField.d.ts +32 -0
- package/dist/NumberField/NumberField.js +126 -0
- package/dist/NumberField/NumberField.js.map +1 -0
- package/dist/NumberField/index.d.ts +3 -0
- package/dist/NumberField/index.js +2 -0
- package/dist/PageNav/PageNav.d.ts +25 -0
- package/dist/PageNav/PageNav.js +57 -0
- package/dist/PageNav/PageNav.js.map +1 -0
- package/dist/PageNav/index.d.ts +3 -0
- package/dist/PageNav/index.js +2 -0
- package/dist/Pages/Pages.js +2 -0
- package/dist/Pages/Pages.js.map +1 -1
- package/dist/PinField/PinField.d.ts +26 -0
- package/dist/PinField/PinField.js +73 -0
- package/dist/PinField/PinField.js.map +1 -0
- package/dist/PinField/index.d.ts +3 -0
- package/dist/PinField/index.js +2 -0
- package/dist/Prose/Prose.d.ts +15 -0
- package/dist/Prose/Prose.js +25 -0
- package/dist/Prose/Prose.js.map +1 -0
- package/dist/Prose/index.d.ts +3 -0
- package/dist/Prose/index.js +2 -0
- package/dist/Quote/Quote.d.ts +19 -0
- package/dist/Quote/Quote.js +52 -0
- package/dist/Quote/Quote.js.map +1 -0
- package/dist/Quote/index.d.ts +3 -0
- package/dist/Quote/index.js +2 -0
- package/dist/Rail/Rail.d.ts +37 -0
- package/dist/Rail/Rail.js +61 -0
- package/dist/Rail/Rail.js.map +1 -0
- package/dist/Rail/index.d.ts +3 -0
- package/dist/Rail/index.js +2 -0
- package/dist/Rating/Rating.js +2 -0
- package/dist/Rating/Rating.js.map +1 -1
- package/dist/Search/Search.js +2 -0
- package/dist/Search/Search.js.map +1 -1
- package/dist/SecretField/SecretField.d.ts +17 -0
- package/dist/SecretField/SecretField.js +59 -0
- package/dist/SecretField/SecretField.js.map +1 -0
- package/dist/SecretField/index.d.ts +3 -0
- package/dist/SecretField/index.js +2 -0
- package/dist/Settings/Settings.js +2 -0
- package/dist/Settings/Settings.js.map +1 -1
- package/dist/Sheet/Sheet.d.ts +8 -3
- package/dist/Sheet/Sheet.js +1 -1
- package/dist/Sheet/Sheet.js.map +1 -1
- package/dist/Sheet/index.d.ts +2 -2
- package/dist/SkipLink/SkipLink.d.ts +22 -0
- package/dist/SkipLink/SkipLink.js +32 -0
- package/dist/SkipLink/SkipLink.js.map +1 -0
- package/dist/SkipLink/index.d.ts +3 -0
- package/dist/SkipLink/index.js +2 -0
- package/dist/SlurpProvider/SlurpProvider.d.ts +7 -1
- package/dist/SlurpProvider/SlurpProvider.js +14 -6
- package/dist/SlurpProvider/SlurpProvider.js.map +1 -1
- package/dist/Steps/Steps.js +2 -0
- package/dist/Steps/Steps.js.map +1 -1
- package/dist/Suggest/Suggest.js +2 -0
- package/dist/Suggest/Suggest.js.map +1 -1
- package/dist/Table/Table.d.ts +12 -0
- package/dist/Table/Table.js +56 -10
- package/dist/Table/Table.js.map +1 -1
- package/dist/Tag/Tag.d.ts +14 -0
- package/dist/Tag/Tag.js +26 -0
- package/dist/Tag/Tag.js.map +1 -0
- package/dist/Tag/index.d.ts +3 -0
- package/dist/Tag/index.js +2 -0
- package/dist/Timeline/Timeline.d.ts +23 -0
- package/dist/Timeline/Timeline.js +49 -0
- package/dist/Timeline/Timeline.js.map +1 -0
- package/dist/Timeline/index.d.ts +3 -0
- package/dist/Timeline/index.js +2 -0
- package/dist/Toast/Toast.js +31 -7
- package/dist/Toast/Toast.js.map +1 -1
- package/dist/Tree/Tree.d.ts +24 -0
- package/dist/Tree/Tree.js +113 -0
- package/dist/Tree/Tree.js.map +1 -0
- package/dist/Tree/index.d.ts +3 -0
- package/dist/Tree/index.js +2 -0
- package/dist/index.d.ts +63 -8
- package/dist/index.js +31 -2
- package/dist/internal/labels.js +12 -0
- package/dist/internal/labels.js.map +1 -0
- package/dist/lib/labels.d.ts +210 -0
- package/dist/lib/labels.js +139 -0
- package/dist/lib/labels.js.map +1 -0
- package/dist/lib/theme.d.ts +134 -4
- package/dist/lib/theme.js.map +1 -1
- package/dist/styles.css +1912 -138
- package/dist/tokens.css +9 -0
- package/dist/utils/focus.d.ts +1 -1
- package/dist/utils/focus.js +2 -2
- package/dist/utils/focus.js.map +1 -1
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/useClipboard.d.ts +14 -0
- package/dist/utils/useClipboard.js +30 -0
- package/dist/utils/useClipboard.js.map +1 -0
- package/dist/utils/useScrollSpy.d.ts +14 -0
- package/dist/utils/useScrollSpy.js +27 -0
- package/dist/utils/useScrollSpy.js.map +1 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Carousel.js","names":[],"sources":["../../src/Carousel/Carousel.tsx"],"sourcesContent":["import { ChevronLeftIcon, ChevronRightIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n Children,\n Fragment,\n useEffect,\n useId,\n useRef,\n type ElementType,\n type KeyboardEvent,\n type ReactNode,\n} from 'react';\n\nimport { Bubble } from '../Bubble/Bubble';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\n\nexport interface CarouselLabels {\n previous: string;\n next: string;\n /** Name of a slide (\"2 di 5\"). */\n slide: (index: number, count: number) => string;\n /** Name of the button of a slide (\"Mostra 2 di 5\"). */\n show: (index: number, count: number) => string;\n /** Name of the group of slide buttons. */\n picker: string;\n}\n\nexport const CAROUSEL_LABELS: CarouselLabels = {\n previous: 'Precedente',\n next: 'Successiva',\n slide: (i, n) => `${i} di ${n}`,\n show: (i, n) => `Mostra ${i} di ${n}`,\n picker: 'Scegli cosa mostrare',\n};\n\nexport interface CarouselOwnProps extends PartsProps<\n 'track' | 'slide' | 'controls' | 'previous' | 'next' | 'dot'\n> {\n /** What it shows (\"Foto del prodotto\"): the name of the carousel. */\n label: string;\n /** The slides: one per child (a Stage, an image…). */\n children: ReactNode;\n /** Slide shown, from 0. */\n index?: number;\n /** Default 0. */\n defaultIndex?: number;\n onIndexChange?: (index: number) => void;\n /** Above this many slides the dots (44px targets each) become a \"2 / 12\" counter. Default 5, which fits a phone. */\n maxDots?: number;\n labels?: Partial<CarouselLabels>;\n}\n\nexport type CarouselProps<E extends ElementType = 'section'> = PolymorphicProps<\n E,\n CarouselOwnProps\n>;\n\nconst reduced = () =>\n typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n\n/** Slide nearest to the track's scroll position (-1 when the track has no layout). */\nfunction visible(track: HTMLElement): number {\n const width = track.clientWidth;\n return width ? Math.round(Math.abs(track.scrollLeft) / width) : -1;\n}\n\n/**\n * Media carousel: one slide at a time on a scroll-snap track (swipe on touch, arrow keys on the focused track), with\n * previous / next and a dot per slide (the current one is a longer pill). It never moves by itself; hidden slides are\n * inert, the shown one is announced politely.\n */\nexport function Carousel<E extends ElementType = 'section'>(props: CarouselProps<E>) {\n const {\n as,\n css,\n className,\n label,\n children,\n index: indexProp,\n defaultIndex = 0,\n onIndexChange,\n maxDots = 5,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Carousel', props as CarouselProps);\n const labels = { ...CAROUSEL_LABELS, ...labelsProp };\n const slides = Children.toArray(children);\n const count = slides.length;\n const [raw, setIndex] = useControlled({\n value: indexProp,\n defaultValue: defaultIndex,\n onChange: onIndexChange,\n });\n const index = Math.min(Math.max(0, count - 1), Math.max(0, raw));\n const trackId = `${useId()}-track`;\n /** Slide a programmatic scroll is heading to: the scroll events on the way do not change the index. */\n const heading = useRef<{ to: number; until: number } | null>(null);\n const Root = (as ?? 'section') as ElementType;\n const styled = useCss('Carousel', 'root', css);\n const { part, style } = useParts('Carousel', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n // The index changed (buttons, keys, a controlled value): bring that slide into view.\n useEffect(() => {\n const t = document.getElementById(trackId);\n if (!t || visible(t) === index) return;\n const slide = t.children[index] as HTMLElement | undefined;\n if (!slide) return;\n heading.current = { to: index, until: performance.now() + 1000 };\n t.scrollTo?.({ left: slide.offsetLeft, behavior: reduced() ? 'auto' : 'smooth' });\n }, [index, trackId]);\n\n const go = (to: number) => {\n const next = Math.min(count - 1, Math.max(0, to));\n if (next !== index) setIndex(next);\n };\n\n // Swipes and scrolling: the slide that snapped into view becomes the current one.\n const latest = useRef({ index, count, setIndex });\n useEffect(() => {\n latest.current = { index, count, setIndex };\n });\n useEffect(() => {\n const t = document.getElementById(trackId);\n if (!t) return;\n const onScroll = (e: Event) => {\n const at = visible(t);\n const h = heading.current;\n if (h) {\n if (at === h.to || e.timeStamp > h.until) heading.current = null;\n else return;\n }\n const { index: now, count: n, setIndex: set } = latest.current;\n if (at >= 0 && at < n && at !== now) set(at);\n };\n t.addEventListener('scroll', onScroll, { passive: true });\n return () => t.removeEventListener('scroll', onScroll);\n }, [trackId]);\n\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.target !== e.currentTarget) return;\n const rtl = getComputedStyle(e.currentTarget).direction === 'rtl';\n const step = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0;\n if (step) go(index + (rtl ? -step : step));\n else if (e.key === 'Home') go(0);\n else if (e.key === 'End') go(count - 1);\n else return;\n e.preventDefault();\n };\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-carousel', styled.className, className)}\n aria-roledescription=\"carousel\"\n aria-label={label}\n {...root}\n >\n {part('track', 'div', {\n id: trackId,\n className: 'slurp-carousel-track',\n tabIndex: 0,\n 'aria-live': 'polite',\n onKeyDown,\n children: slides.map((s, i) => (\n <Fragment key={i}>\n {part('slide', 'div', {\n role: 'group',\n 'aria-roledescription': 'slide',\n 'aria-label': labels.slide(i + 1, count),\n className: 'slurp-carousel-slide',\n 'data-current': i === index ? '' : undefined,\n inert: i !== index,\n children: s,\n })}\n </Fragment>\n )),\n })}\n {count > 1 &&\n part('controls', 'div', {\n className: 'slurp-carousel-controls',\n children: (\n <>\n {part('previous', Bubble, {\n className: 'slurp-carousel-previous',\n label: labels.previous,\n appearance: 'soft',\n disabled: index === 0,\n onClick: () => go(index - 1),\n children: <ChevronLeftIcon size={20} />,\n })}\n {count <= maxDots ? (\n <div className=\"slurp-carousel-dots\" role=\"group\" aria-label={labels.picker}>\n {slides.map((_, i) => (\n <Fragment key={i}>\n {part('dot', 'button', {\n type: 'button',\n className: 'slurp-carousel-dot',\n 'aria-label': labels.show(i + 1, count),\n 'aria-current': i === index ? 'true' : undefined,\n onClick: () => go(i),\n })}\n </Fragment>\n ))}\n </div>\n ) : (\n <span className=\"slurp-carousel-status\" aria-hidden=\"true\">\n {index + 1} / {count}\n </span>\n )}\n {part('next', Bubble, {\n className: 'slurp-carousel-next',\n label: labels.next,\n appearance: 'soft',\n disabled: index === count - 1,\n onClick: () => go(index + 1),\n children: <ChevronRightIcon size={20} />,\n })}\n </>\n ),\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AA8BA,MAAa,kBAAkC;CAC7C,UAAU;CACV,MAAM;CACN,QAAQ,GAAG,MAAM,GAAG,EAAE,MAAM;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AAU,QAAQ;MAC5B,eAAe,GAAG,QAAQ,CAAC;MAC3B,UAAU,oBAAC,kBAAD,EAAkB,MAAM,GAAK,CAAA;KACzC,CAAC;IACD,EAAA,CAAA;GAEN,CAAC,CACC;;CACN,EAAA,CAAA;AAEN"}
|
|
1
|
+
{"version":3,"file":"Carousel.js","names":[],"sources":["../../src/Carousel/Carousel.tsx"],"sourcesContent":["import { ChevronLeftIcon, ChevronRightIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport {\n Children,\n Fragment,\n useEffect,\n useId,\n useRef,\n type ElementType,\n type KeyboardEvent,\n type ReactNode,\n} from 'react';\n\nimport { useLabels } from '../internal/labels';\nimport { Bubble } from '../Bubble/Bubble';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\n\nexport interface CarouselLabels {\n previous: string;\n next: string;\n /** Name of a slide (\"2 di 5\"). */\n slide: (index: number, count: number) => string;\n /** Name of the button of a slide (\"Mostra 2 di 5\"). */\n show: (index: number, count: number) => string;\n /** Name of the group of slide buttons. */\n picker: string;\n}\n\nexport const CAROUSEL_LABELS: CarouselLabels = {\n previous: 'Precedente',\n next: 'Successiva',\n slide: (i, n) => `${i} di ${n}`,\n show: (i, n) => `Mostra ${i} di ${n}`,\n picker: 'Scegli cosa mostrare',\n};\n\nexport interface CarouselOwnProps extends PartsProps<\n 'track' | 'slide' | 'controls' | 'previous' | 'next' | 'dot'\n> {\n /** What it shows (\"Foto del prodotto\"): the name of the carousel. */\n label: string;\n /** The slides: one per child (a Stage, an image…). */\n children: ReactNode;\n /** Slide shown, from 0. */\n index?: number;\n /** Default 0. */\n defaultIndex?: number;\n onIndexChange?: (index: number) => void;\n /** Above this many slides the dots (44px targets each) become a \"2 / 12\" counter. Default 5, which fits a phone. */\n maxDots?: number;\n labels?: Partial<CarouselLabels>;\n}\n\nexport type CarouselProps<E extends ElementType = 'section'> = PolymorphicProps<\n E,\n CarouselOwnProps\n>;\n\nconst reduced = () =>\n typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n\n/** Slide nearest to the track's scroll position (-1 when the track has no layout). */\nfunction visible(track: HTMLElement): number {\n const width = track.clientWidth;\n return width ? Math.round(Math.abs(track.scrollLeft) / width) : -1;\n}\n\n/**\n * Media carousel: one slide at a time on a scroll-snap track (swipe on touch, arrow keys on the focused track), with\n * previous / next and a dot per slide (the current one is a longer pill). It never moves by itself; hidden slides are\n * inert, the shown one is announced politely.\n */\nexport function Carousel<E extends ElementType = 'section'>(props: CarouselProps<E>) {\n const {\n as,\n css,\n className,\n label,\n children,\n index: indexProp,\n defaultIndex = 0,\n onIndexChange,\n maxDots = 5,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Carousel', props as CarouselProps);\n const labels = { ...CAROUSEL_LABELS, ...useLabels('Carousel'), ...labelsProp };\n const slides = Children.toArray(children);\n const count = slides.length;\n const [raw, setIndex] = useControlled({\n value: indexProp,\n defaultValue: defaultIndex,\n onChange: onIndexChange,\n });\n const index = Math.min(Math.max(0, count - 1), Math.max(0, raw));\n const trackId = `${useId()}-track`;\n /** Slide a programmatic scroll is heading to: the scroll events on the way do not change the index. */\n const heading = useRef<{ to: number; until: number } | null>(null);\n const Root = (as ?? 'section') as ElementType;\n const styled = useCss('Carousel', 'root', css);\n const { part, style } = useParts('Carousel', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n\n // The index changed (buttons, keys, a controlled value): bring that slide into view.\n useEffect(() => {\n const t = document.getElementById(trackId);\n if (!t || visible(t) === index) return;\n const slide = t.children[index] as HTMLElement | undefined;\n if (!slide) return;\n heading.current = { to: index, until: performance.now() + 1000 };\n t.scrollTo?.({ left: slide.offsetLeft, behavior: reduced() ? 'auto' : 'smooth' });\n }, [index, trackId]);\n\n const go = (to: number) => {\n const next = Math.min(count - 1, Math.max(0, to));\n if (next !== index) setIndex(next);\n };\n\n // Swipes and scrolling: the slide that snapped into view becomes the current one.\n const latest = useRef({ index, count, setIndex });\n useEffect(() => {\n latest.current = { index, count, setIndex };\n });\n useEffect(() => {\n const t = document.getElementById(trackId);\n if (!t) return;\n const onScroll = (e: Event) => {\n const at = visible(t);\n const h = heading.current;\n if (h) {\n if (at === h.to || e.timeStamp > h.until) heading.current = null;\n else return;\n }\n const { index: now, count: n, setIndex: set } = latest.current;\n if (at >= 0 && at < n && at !== now) set(at);\n };\n t.addEventListener('scroll', onScroll, { passive: true });\n return () => t.removeEventListener('scroll', onScroll);\n }, [trackId]);\n\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.target !== e.currentTarget) return;\n const rtl = getComputedStyle(e.currentTarget).direction === 'rtl';\n const step = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0;\n if (step) go(index + (rtl ? -step : step));\n else if (e.key === 'Home') go(0);\n else if (e.key === 'End') go(count - 1);\n else return;\n e.preventDefault();\n };\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-carousel', styled.className, className)}\n aria-roledescription=\"carousel\"\n aria-label={label}\n {...root}\n >\n {part('track', 'div', {\n id: trackId,\n className: 'slurp-carousel-track',\n tabIndex: 0,\n 'aria-live': 'polite',\n onKeyDown,\n children: slides.map((s, i) => (\n <Fragment key={i}>\n {part('slide', 'div', {\n role: 'group',\n 'aria-roledescription': 'slide',\n 'aria-label': labels.slide(i + 1, count),\n className: 'slurp-carousel-slide',\n 'data-current': i === index ? '' : undefined,\n inert: i !== index,\n children: s,\n })}\n </Fragment>\n )),\n })}\n {count > 1 &&\n part('controls', 'div', {\n className: 'slurp-carousel-controls',\n children: (\n <>\n {part('previous', Bubble, {\n className: 'slurp-carousel-previous',\n label: labels.previous,\n appearance: 'soft',\n disabled: index === 0,\n onClick: () => go(index - 1),\n children: <ChevronLeftIcon size={20} />,\n })}\n {count <= maxDots ? (\n <div className=\"slurp-carousel-dots\" role=\"group\" aria-label={labels.picker}>\n {slides.map((_, i) => (\n <Fragment key={i}>\n {part('dot', 'button', {\n type: 'button',\n className: 'slurp-carousel-dot',\n 'aria-label': labels.show(i + 1, count),\n 'aria-current': i === index ? 'true' : undefined,\n onClick: () => go(i),\n })}\n </Fragment>\n ))}\n </div>\n ) : (\n <span className=\"slurp-carousel-status\" aria-hidden=\"true\">\n {index + 1} / {count}\n </span>\n )}\n {part('next', Bubble, {\n className: 'slurp-carousel-next',\n label: labels.next,\n appearance: 'soft',\n disabled: index === count - 1,\n onClick: () => go(index + 1),\n children: <ChevronRightIcon size={20} />,\n })}\n </>\n ),\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;AA+BA,MAAa,kBAAkC;CAC7C,UAAU;CACV,MAAM;CACN,QAAQ,GAAG,MAAM,GAAG,EAAE,MAAM;CAC5B,OAAO,GAAG,MAAM,UAAU,EAAE,MAAM;CAClC,QAAQ;AACV;AAwBA,MAAM,gBACJ,OAAO,eAAe,cAAc,WAAW,kCAAkC,CAAC,CAAC;;AAGrF,SAAS,QAAQ,OAA4B;CAC3C,MAAM,QAAQ,MAAM;CACpB,OAAO,QAAQ,KAAK,MAAM,KAAK,IAAI,MAAM,UAAU,IAAI,KAAK,IAAI;AAClE;;;;;;AAOA,SAAgB,SAA4C,OAAyB;CACnF,MAAM,EACJ,IACA,KACA,WACA,OACA,UACA,OAAO,WACP,eAAe,GACf,eACA,UAAU,GACV,QAAQ,YACR,OACA,WACA,YACA,GAAG,SACD,cAAc,YAAY,KAAsB;CACpD,MAAM,SAAS;EAAE,GAAG;EAAiB,GAAG,UAAU,UAAU;EAAG,GAAG;CAAW;CAC7E,MAAM,SAAS,SAAS,QAAQ,QAAQ;CACxC,MAAM,QAAQ,OAAO;CACrB,MAAM,CAAC,KAAK,YAAY,cAAc;EACpC,OAAO;EACP,cAAc;EACd,UAAU;CACZ,CAAC;CACD,MAAM,QAAQ,KAAK,IAAI,KAAK,I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AG,QAAQ,CAAC;MAC3B,UAAU,oBAAC,iBAAD,EAAiB,MAAM,GAAK,CAAA;KACxC,CAAC;KACA,SAAS,UACR,oBAAC,OAAD;MAAK,WAAU;MAAsB,MAAK;MAAQ,cAAY,OAAO;MAClE,UAAA,OAAO,KAAK,GAAG,MACd,oBAAC,UAAD,EAAA,UACG,KAAK,OAAO,UAAU;OACrB,MAAM;OACN,WAAW;OACX,cAAc,OAAO,KAAK,IAAI,GAAG,KAAK;OACtC,gBAAgB,MAAM,QAAQ,SAAS,KAAA;OACvC,eAAe,GAAG,CAAC;MACrB,CAAC,EACO,GARK,CAQL,CACX;KACE,CAAA,IAEL,qBAAC,QAAD;MAAM,WAAU;MAAwB,eAAY;MAApD,UAAA;OACG,QAAQ;OAAE;OAAI;MACX;;KAEP,KAAK,QAAQ,QAAQ;MACpB,WAAW;MACX,OAAO,OAAO;MACd,YAAY;MACZ,UAAU,UAAU,QAAQ;MAC5B,eAAe,GAAG,QAAQ,CAAC;MAC3B,UAAU,oBAAC,kBAAD,EAAkB,MAAM,GAAK,CAAA;KACzC,CAAC;IACD,EAAA,CAAA;GAEN,CAAC,CACC;;CACN,EAAA,CAAA;AAEN"}
|
package/dist/Choice/Choice.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
2
3
|
import { cx } from "../utils/src/index.js";
|
|
3
4
|
import { useAnimationRoot } from "../internal/animation.js";
|
|
4
5
|
import { useCss, useThemeProps } from "../internal/styled.js";
|
|
@@ -18,6 +19,7 @@ function Choice(props) {
|
|
|
18
19
|
const { as, css, className, label, options, value: valueProp, defaultValue = null, onValueChange, name, disabled, width = 280, placement, labels: labelsProp, ...rest } = useThemeProps("Choice", props);
|
|
19
20
|
const labels = {
|
|
20
21
|
...CHOICE_LABELS,
|
|
22
|
+
...useLabels("Choice"),
|
|
21
23
|
...labelsProp
|
|
22
24
|
};
|
|
23
25
|
const [value, setValue] = useControlled({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Choice.js","names":[],"sources":["../../src/Choice/Choice.tsx"],"sourcesContent":["import { CheckIcon, ChevronDownIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { useId, useRef, type ElementType, type KeyboardEvent, type ReactNode } from 'react';\n\nimport { Bloom, type BloomPlacement } from '../Bloom/Bloom';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\nimport { moveFocus } from '../utils/focus';\nimport { useControlled } from '../utils/useControlled';\n\nexport interface ChoiceOption<V extends string = string> {\n value: V;\n label: string;\n icon?: ReactNode;\n disabled?: boolean;\n}\n\nexport interface ChoiceLabels {\n /** Trigger text while nothing is chosen. */\n placeholder: string;\n}\n\nexport const CHOICE_LABELS: ChoiceLabels = { placeholder: 'Scegli…' };\n\nexport interface ChoiceOwnProps<V extends string = string> {\n /** Visible label (\"Ordina per\"). */\n label: ReactNode;\n options: ChoiceOption<V>[];\n value?: V | null;\n defaultValue?: V | null;\n onValueChange?: (value: V) => void;\n /** Form field name: a hidden input carries the value. */\n name?: string;\n disabled?: boolean;\n /** Panel width. Default 280. */\n width?: number;\n placement?: BloomPlacement;\n labels?: Partial<ChoiceLabels>;\n}\n\nexport type ChoiceProps<\n V extends string = string,\n E extends ElementType = 'div',\n> = PolymorphicProps<E, ChoiceOwnProps<V>>;\n\n/**\n * Select: the trigger **becomes** the list (Bloom). ArrowDown / ArrowUp / Enter / Space open it on the trigger;\n * in the list arrows move, Enter or Space choose, Escape closes and gives focus back.\n */\nexport function Choice<V extends string = string, E extends ElementType = 'div'>(\n props: ChoiceProps<V, E>,\n) {\n const {\n as,\n css,\n className,\n label,\n options,\n value: valueProp,\n defaultValue = null,\n onValueChange,\n name,\n disabled,\n width = 280,\n placement,\n labels: labelsProp,\n ...rest\n } = useThemeProps('Choice', props as unknown as ChoiceProps);\n const labels = { ...CHOICE_LABELS, ...labelsProp };\n const [value, setValue] = useControlled<string | null>({\n value: valueProp,\n defaultValue,\n onChange: onValueChange as ((v: string | null) => void) | undefined,\n });\n const [open, setOpen] = useControlled({ value: undefined, defaultValue: false });\n const list = useRef<HTMLDivElement>(null);\n const labelId = useId();\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Choice', 'root', css);\n const root = useAnimationRoot(rest);\n const chosen = options.find((o) => o.value === value);\n\n const choose = (o: ChoiceOption, close: (restore?: boolean) => void) => {\n if (o.disabled) return;\n setValue(o.value);\n close(true);\n };\n\n return (\n <>\n {styled.style}\n <Root className={cx('slurp-choice', styled.className, className)} {...root}>\n <span id={labelId} className=\"slurp-choice-label\">\n {label}\n </span>\n <Bloom\n open={open}\n onOpenChange={setOpen}\n role=\"listbox\"\n width={width}\n placement={placement}\n disabled={disabled}\n trigger={\n <>\n <span className={cx('slurp-choice-value', !chosen && 'slurp-choice-placeholder')}>\n {chosen?.label ?? labels.placeholder}\n </span>\n <ChevronDownIcon size={18} />\n </>\n }\n partProps={{\n trigger: {\n 'aria-labelledby': `${labelId} ${labelId}-value`,\n onKeyDown: (e: KeyboardEvent) => {\n if (!open && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) {\n e.preventDefault();\n setOpen(true);\n }\n },\n },\n panel: { 'aria-labelledby': labelId },\n }}\n >\n {(close) => (\n <div\n ref={list}\n className=\"slurp-choice-list\"\n onKeyDown={(e) => {\n if (moveFocus(e, list.current, '[role=\"option\"]')) return;\n if (e.key === 'Enter' || e.key === ' ') {\n const at = (e.target as HTMLElement).closest<HTMLElement>('[role=\"option\"]');\n const o = options.find((x) => x.value === at?.dataset.value);\n if (o) {\n e.preventDefault();\n choose(o, close);\n }\n }\n }}\n >\n {options.map((o) => {\n const on = o.value === value;\n return (\n <div\n key={o.value}\n role=\"option\"\n tabIndex={-1}\n aria-selected={on}\n aria-disabled={o.disabled || undefined}\n data-value={o.value}\n className=\"slurp-bloom-item\"\n onClick={() => choose(o, close)}\n >\n {o.icon != null && (\n <span className=\"slurp-bloom-item-icon\" aria-hidden=\"true\">\n {o.icon}\n </span>\n )}\n <span className=\"slurp-bloom-item-label\">{o.label}</span>\n {on && (\n <span className=\"slurp-bloom-item-check\" aria-hidden=\"true\">\n <CheckIcon size={18} />\n </span>\n )}\n </div>\n );\n })}\n </div>\n )}\n </Bloom>\n <span id={`${labelId}-value`} hidden>\n {chosen?.label ?? labels.placeholder}\n </span>\n {name && <input type=\"hidden\" name={name} value={value ?? ''} />}\n </Root>\n </>\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Choice.js","names":[],"sources":["../../src/Choice/Choice.tsx"],"sourcesContent":["import { CheckIcon, ChevronDownIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { useId, useRef, type ElementType, type KeyboardEvent, type ReactNode } from 'react';\n\nimport { useLabels } from '../internal/labels';\nimport { Bloom, type BloomPlacement } from '../Bloom/Bloom';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\nimport { moveFocus } from '../utils/focus';\nimport { useControlled } from '../utils/useControlled';\n\nexport interface ChoiceOption<V extends string = string> {\n value: V;\n label: string;\n icon?: ReactNode;\n disabled?: boolean;\n}\n\nexport interface ChoiceLabels {\n /** Trigger text while nothing is chosen. */\n placeholder: string;\n}\n\nexport const CHOICE_LABELS: ChoiceLabels = { placeholder: 'Scegli…' };\n\nexport interface ChoiceOwnProps<V extends string = string> {\n /** Visible label (\"Ordina per\"). */\n label: ReactNode;\n options: ChoiceOption<V>[];\n value?: V | null;\n defaultValue?: V | null;\n onValueChange?: (value: V) => void;\n /** Form field name: a hidden input carries the value. */\n name?: string;\n disabled?: boolean;\n /** Panel width. Default 280. */\n width?: number;\n placement?: BloomPlacement;\n labels?: Partial<ChoiceLabels>;\n}\n\nexport type ChoiceProps<\n V extends string = string,\n E extends ElementType = 'div',\n> = PolymorphicProps<E, ChoiceOwnProps<V>>;\n\n/**\n * Select: the trigger **becomes** the list (Bloom). ArrowDown / ArrowUp / Enter / Space open it on the trigger;\n * in the list arrows move, Enter or Space choose, Escape closes and gives focus back.\n */\nexport function Choice<V extends string = string, E extends ElementType = 'div'>(\n props: ChoiceProps<V, E>,\n) {\n const {\n as,\n css,\n className,\n label,\n options,\n value: valueProp,\n defaultValue = null,\n onValueChange,\n name,\n disabled,\n width = 280,\n placement,\n labels: labelsProp,\n ...rest\n } = useThemeProps('Choice', props as unknown as ChoiceProps);\n const labels = { ...CHOICE_LABELS, ...useLabels('Choice'), ...labelsProp };\n const [value, setValue] = useControlled<string | null>({\n value: valueProp,\n defaultValue,\n onChange: onValueChange as ((v: string | null) => void) | undefined,\n });\n const [open, setOpen] = useControlled({ value: undefined, defaultValue: false });\n const list = useRef<HTMLDivElement>(null);\n const labelId = useId();\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Choice', 'root', css);\n const root = useAnimationRoot(rest);\n const chosen = options.find((o) => o.value === value);\n\n const choose = (o: ChoiceOption, close: (restore?: boolean) => void) => {\n if (o.disabled) return;\n setValue(o.value);\n close(true);\n };\n\n return (\n <>\n {styled.style}\n <Root className={cx('slurp-choice', styled.className, className)} {...root}>\n <span id={labelId} className=\"slurp-choice-label\">\n {label}\n </span>\n <Bloom\n open={open}\n onOpenChange={setOpen}\n role=\"listbox\"\n width={width}\n placement={placement}\n disabled={disabled}\n trigger={\n <>\n <span className={cx('slurp-choice-value', !chosen && 'slurp-choice-placeholder')}>\n {chosen?.label ?? labels.placeholder}\n </span>\n <ChevronDownIcon size={18} />\n </>\n }\n partProps={{\n trigger: {\n 'aria-labelledby': `${labelId} ${labelId}-value`,\n onKeyDown: (e: KeyboardEvent) => {\n if (!open && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) {\n e.preventDefault();\n setOpen(true);\n }\n },\n },\n panel: { 'aria-labelledby': labelId },\n }}\n >\n {(close) => (\n <div\n ref={list}\n className=\"slurp-choice-list\"\n onKeyDown={(e) => {\n if (moveFocus(e, list.current, '[role=\"option\"]')) return;\n if (e.key === 'Enter' || e.key === ' ') {\n const at = (e.target as HTMLElement).closest<HTMLElement>('[role=\"option\"]');\n const o = options.find((x) => x.value === at?.dataset.value);\n if (o) {\n e.preventDefault();\n choose(o, close);\n }\n }\n }}\n >\n {options.map((o) => {\n const on = o.value === value;\n return (\n <div\n key={o.value}\n role=\"option\"\n tabIndex={-1}\n aria-selected={on}\n aria-disabled={o.disabled || undefined}\n data-value={o.value}\n className=\"slurp-bloom-item\"\n onClick={() => choose(o, close)}\n >\n {o.icon != null && (\n <span className=\"slurp-bloom-item-icon\" aria-hidden=\"true\">\n {o.icon}\n </span>\n )}\n <span className=\"slurp-bloom-item-label\">{o.label}</span>\n {on && (\n <span className=\"slurp-bloom-item-check\" aria-hidden=\"true\">\n <CheckIcon size={18} />\n </span>\n )}\n </div>\n );\n })}\n </div>\n )}\n </Bloom>\n <span id={`${labelId}-value`} hidden>\n {chosen?.label ?? labels.placeholder}\n </span>\n {name && <input type=\"hidden\" name={name} value={value ?? ''} />}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAwBA,MAAa,gBAA8B,EAAE,aAAa,UAAU;;;;;AA2BpE,SAAgB,OACd,OACA;CACA,MAAM,EACJ,IACA,KACA,WACA,OACA,SACA,OAAO,WACP,eAAe,MACf,eACA,MACA,UACA,QAAQ,KACR,WACA,QAAQ,YACR,GAAG,SACD,cAAc,UAAU,KAA+B;CAC3D,MAAM,SAAS;EAAE,GAAG;EAAe,GAAG,UAAU,QAAQ;EAAG,GAAG;CAAW;CACzE,MAAM,CAAC,OAAO,YAAY,cAA6B;EACrD,OAAO;EACP;EACA,UAAU;CACZ,CAAC;CACD,MAAM,CAAC,MAAM,WAAW,cAAc;EAAE,OAAO,KAAA;EAAW,cAAc;CAAM,CAAC;CAC/E,MAAM,OAAO,OAAuB,IAAI;CACxC,MAAM,UAAU,MAAM;CACtB,M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AAI,QAAQ,KAAK;OAC3D,IAAI,GAAG;QACL,EAAE,eAAe;QACjB,OAAO,GAAG,KAAK;OACjB;MACF;KACF;KAEC,UAAA,QAAQ,KAAK,MAAM;MAClB,MAAM,KAAK,EAAE,UAAU;MACvB,OACE,qBAAC,OAAD;OAEE,MAAK;OACL,UAAU;OACV,iBAAe;OACf,iBAAe,EAAE,YAAY,KAAA;OAC7B,cAAY,EAAE;OACd,WAAU;OACV,eAAe,OAAO,GAAG,KAAK;OARhC,UAAA;QAUG,EAAE,QAAQ,QACT,oBAAC,QAAD;SAAM,WAAU;SAAwB,eAAY;SACjD,UAAA,EAAE;QACC,CAAA;QAER,oBAAC,QAAD;SAAM,WAAU;SAA0B,UAAA,EAAE;QAAY,CAAA;QACvD,MACC,oBAAC,QAAD;SAAM,WAAU;SAAyB,eAAY;SACnD,UAAA,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA;QAClB,CAAA;OAEL;MApBE,GAAA,EAAE,KAoBJ;KAET,CAAC;IACE,CAAA;GAEF,CAAA;GACP,oBAAC,QAAD;IAAM,IAAI,GAAG,QAAQ;IAAS,QAAA;IAC3B,UAAA,QAAQ,SAAS,OAAO;GACrB,CAAA;GACL,QAAQ,oBAAC,SAAD;IAAO,MAAK;IAAe;IAAM,OAAO,SAAS;GAAK,CAAA;EAC3D;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
import { PartsProps, PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType, ReactNode } from "react";
|
|
4
|
+
export interface CodeLabels {
|
|
5
|
+
/** Name of the copy button. */
|
|
6
|
+
copy: string;
|
|
7
|
+
/** Its name for two seconds after a copy. */
|
|
8
|
+
copied: string;
|
|
9
|
+
/** Name of the scrollable code block when there is no filename. */
|
|
10
|
+
region: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const CODE_LABELS: CodeLabels;
|
|
13
|
+
export interface CodeOwnProps extends PartsProps<'bar' | 'filename' | 'copy' | 'pre'> {
|
|
14
|
+
/** The code as text: shown as is, and what Copy puts on the clipboard. */
|
|
15
|
+
code?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The same code already highlighted (HTML from shiki, Prism…). Shown instead of `code`; `code` is still what gets
|
|
18
|
+
* copied (or the text of this markup when there is no `code`).
|
|
19
|
+
*/
|
|
20
|
+
html?: string;
|
|
21
|
+
/** Your own markup inside <code>, instead of `code` or `html`. */
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
/** A file name or a label above the code ("main.tsx", "Terminale"). */
|
|
24
|
+
filename?: ReactNode;
|
|
25
|
+
/** Language, for the record (`data-language`) and for highlighters. */
|
|
26
|
+
language?: string;
|
|
27
|
+
/** Show the copy button. Default true. */
|
|
28
|
+
copyable?: boolean;
|
|
29
|
+
labels?: Partial<CodeLabels>;
|
|
30
|
+
}
|
|
31
|
+
export type CodeProps<E extends ElementType = 'figure'> = PolymorphicProps<E, CodeOwnProps>;
|
|
32
|
+
/**
|
|
33
|
+
* A block of code: an optional file name, a copy button that says when it worked, and a region that scrolls on its
|
|
34
|
+
* own (reachable with Tab). Highlighting is yours to bring: pass `html` from any highlighter; its colours map onto
|
|
35
|
+
* the design system through `--slurp-code-*` (shiki's CSS variables are mapped too).
|
|
36
|
+
*/
|
|
37
|
+
export declare function Code<E extends ElementType = 'figure'>(props: CodeProps<E>): import("react").JSX.Element;
|
|
38
|
+
//# sourceMappingURL=Code.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
3
|
+
import { cx } from "../utils/src/index.js";
|
|
4
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
5
|
+
import { useCss, useParts, useThemeProps } from "../internal/styled.js";
|
|
6
|
+
import { Bubble } from "../Bubble/Bubble.js";
|
|
7
|
+
import { useClipboard } from "../utils/useClipboard.js";
|
|
8
|
+
import { useId } from "react";
|
|
9
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { CheckIcon, CopyIcon } from "@slurp-ui/icons";
|
|
11
|
+
// src/Code/Code.tsx
|
|
12
|
+
const CODE_LABELS = {
|
|
13
|
+
copy: "Copia il codice",
|
|
14
|
+
copied: "Copiato",
|
|
15
|
+
region: "Codice"
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A block of code: an optional file name, a copy button that says when it worked, and a region that scrolls on its
|
|
19
|
+
* own (reachable with Tab). Highlighting is yours to bring: pass `html` from any highlighter; its colours map onto
|
|
20
|
+
* the design system through `--slurp-code-*` (shiki's CSS variables are mapped too).
|
|
21
|
+
*/
|
|
22
|
+
function Code(props) {
|
|
23
|
+
const { as, css, className, code, html, children, filename, language, copyable = true, labels: labelsProp, parts, partProps, classNames, ...rest } = useThemeProps("Code", props);
|
|
24
|
+
const labels = {
|
|
25
|
+
...CODE_LABELS,
|
|
26
|
+
...useLabels("Code"),
|
|
27
|
+
...labelsProp
|
|
28
|
+
};
|
|
29
|
+
const Root = as ?? "figure";
|
|
30
|
+
const styled = useCss("Code", "root", css);
|
|
31
|
+
const { part, style } = useParts("Code", {
|
|
32
|
+
parts,
|
|
33
|
+
partProps,
|
|
34
|
+
classNames
|
|
35
|
+
});
|
|
36
|
+
const root = useAnimationRoot(rest);
|
|
37
|
+
const { copy, copied } = useClipboard();
|
|
38
|
+
const bodyId = useId();
|
|
39
|
+
const regionName = typeof filename === "string" ? filename : language ?? labels.region;
|
|
40
|
+
const content = children ?? (html != null ? /* @__PURE__ */ jsx("code", { dangerouslySetInnerHTML: { __html: html } }) : /* @__PURE__ */ jsx("code", { children: code }));
|
|
41
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
42
|
+
styled.style,
|
|
43
|
+
style,
|
|
44
|
+
/* @__PURE__ */ jsxs(Root, {
|
|
45
|
+
className: cx("slurp-code", styled.className, className),
|
|
46
|
+
"data-language": language,
|
|
47
|
+
...root,
|
|
48
|
+
children: [
|
|
49
|
+
(filename != null || copyable) && part("bar", "div", {
|
|
50
|
+
className: "slurp-code-bar",
|
|
51
|
+
children: /* @__PURE__ */ jsxs(Fragment$1, { children: [part("filename", "span", {
|
|
52
|
+
className: "slurp-code-filename",
|
|
53
|
+
children: filename
|
|
54
|
+
}), copyable && part("copy", Bubble, {
|
|
55
|
+
className: "slurp-code-copy",
|
|
56
|
+
size: "sm",
|
|
57
|
+
label: copied ? labels.copied : labels.copy,
|
|
58
|
+
"data-copied": copied || void 0,
|
|
59
|
+
onClick: () => void copy(code ?? document.getElementById(bodyId)?.textContent ?? ""),
|
|
60
|
+
children: copied ? /* @__PURE__ */ jsx(CheckIcon, { size: 18 }) : /* @__PURE__ */ jsx(CopyIcon, { size: 18 })
|
|
61
|
+
})] })
|
|
62
|
+
}),
|
|
63
|
+
part("pre", "pre", {
|
|
64
|
+
id: bodyId,
|
|
65
|
+
className: "slurp-code-pre",
|
|
66
|
+
tabIndex: 0,
|
|
67
|
+
role: "group",
|
|
68
|
+
"aria-label": regionName,
|
|
69
|
+
children: content
|
|
70
|
+
}),
|
|
71
|
+
copyable && /* @__PURE__ */ jsx("span", {
|
|
72
|
+
className: "slurp-visually-hidden",
|
|
73
|
+
role: "status",
|
|
74
|
+
children: copied ? labels.copied : ""
|
|
75
|
+
})
|
|
76
|
+
]
|
|
77
|
+
})
|
|
78
|
+
] });
|
|
79
|
+
}
|
|
80
|
+
export { CODE_LABELS, Code };
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=Code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Code.js","names":[],"sources":["../../src/Code/Code.tsx"],"sourcesContent":["import { CheckIcon, CopyIcon } from '@slurp-ui/icons';\nimport { cx } from '@slurp-ui/utils';\nimport { useId, type ElementType, type ReactNode } from 'react';\n\nimport { Bubble } from '../Bubble/Bubble';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useLabels } from '../internal/labels';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { useClipboard } from '../utils/useClipboard';\n\nexport interface CodeLabels {\n /** Name of the copy button. */\n copy: string;\n /** Its name for two seconds after a copy. */\n copied: string;\n /** Name of the scrollable code block when there is no filename. */\n region: string;\n}\n\nexport const CODE_LABELS: CodeLabels = {\n copy: 'Copia il codice',\n copied: 'Copiato',\n region: 'Codice',\n};\n\nexport interface CodeOwnProps extends PartsProps<'bar' | 'filename' | 'copy' | 'pre'> {\n /** The code as text: shown as is, and what Copy puts on the clipboard. */\n code?: string;\n /**\n * The same code already highlighted (HTML from shiki, Prism…). Shown instead of `code`; `code` is still what gets\n * copied (or the text of this markup when there is no `code`).\n */\n html?: string;\n /** Your own markup inside <code>, instead of `code` or `html`. */\n children?: ReactNode;\n /** A file name or a label above the code (\"main.tsx\", \"Terminale\"). */\n filename?: ReactNode;\n /** Language, for the record (`data-language`) and for highlighters. */\n language?: string;\n /** Show the copy button. Default true. */\n copyable?: boolean;\n labels?: Partial<CodeLabels>;\n}\n\nexport type CodeProps<E extends ElementType = 'figure'> = PolymorphicProps<E, CodeOwnProps>;\n\n/**\n * A block of code: an optional file name, a copy button that says when it worked, and a region that scrolls on its\n * own (reachable with Tab). Highlighting is yours to bring: pass `html` from any highlighter; its colours map onto\n * the design system through `--slurp-code-*` (shiki's CSS variables are mapped too).\n */\nexport function Code<E extends ElementType = 'figure'>(props: CodeProps<E>) {\n const {\n as,\n css,\n className,\n code,\n html,\n children,\n filename,\n language,\n copyable = true,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Code', props as CodeProps);\n const labels = { ...CODE_LABELS, ...useLabels('Code'), ...labelsProp };\n const Root = (as ?? 'figure') as ElementType;\n const styled = useCss('Code', 'root', css);\n const { part, style } = useParts('Code', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n const { copy, copied } = useClipboard();\n const bodyId = useId();\n const regionName = typeof filename === 'string' ? filename : (language ?? labels.region);\n\n const content =\n children ??\n (html != null ? <code dangerouslySetInnerHTML={{ __html: html }} /> : <code>{code}</code>);\n\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-code', styled.className, className)}\n data-language={language}\n {...root}\n >\n {(filename != null || copyable) &&\n part('bar', 'div', {\n className: 'slurp-code-bar',\n children: (\n <>\n {part('filename', 'span', {\n className: 'slurp-code-filename',\n children: filename,\n })}\n {copyable &&\n part('copy', Bubble, {\n className: 'slurp-code-copy',\n size: 'sm',\n label: copied ? labels.copied : labels.copy,\n 'data-copied': copied || undefined,\n onClick: () =>\n void copy(code ?? document.getElementById(bodyId)?.textContent ?? ''),\n children: copied ? <CheckIcon size={18} /> : <CopyIcon size={18} />,\n })}\n </>\n ),\n })}\n {part('pre', 'pre', {\n id: bodyId,\n className: 'slurp-code-pre',\n tabIndex: 0,\n // A named group, not a region: a page has many code blocks, and landmarks must be unique.\n role: 'group',\n 'aria-label': regionName,\n children: content,\n })}\n {copyable && (\n <span className=\"slurp-visually-hidden\" role=\"status\">\n {copied ? labels.copied : ''}\n </span>\n )}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;AAoBA,MAAa,cAA0B;CACrC,MAAM;CACN,QAAQ;CACR,QAAQ;AACV;;;;;;AA4BA,SAAgB,KAAuC,OAAqB;CAC1E,MAAM,EACJ,IACA,KACA,WACA,MACA,MACA,UACA,UACA,UACA,WAAW,MACX,QAAQ,YACR,OACA,WACA,YACA,GAAG,SACD,cAAc,QAAQ,KAAkB;CAC5C,MAAM,SAAS;EAAE,GAAG;EAAa,GAAG,UAAU,MAAM;EAAG,GAAG;CAAW;CACrE,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,QAAQ,QAAQ,GAAG;CACzC,MAAM,EAAE,MAAM,UAAU,SAAS,QAAQ;EAAE;EAAO;EAAW;CAAW,CAAC;CACzE,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,EAAE,MAAM,WAAW,aAAa;CACtC,MAAM,SAAS,MAAM;CACrB,MAAM,aAAa,OAAO,aAAa,WAAW,WAAY,YAAY,OAAO;CAEjF,MAAM,UACJ,aACC,QAAQ,OAAO,oBAAC,QAAD,EAAM,yBAAyB,EAAE,QAAQ,KAAK,EAAI,CAAA,IAAI,oBAAC,QAAD,EAAA,UAAO,KAAW,CAAA;CAE1F,OACE,qBAAA,YAAA,EAAA,UAAA;EACG,OAAO;EACP;EACD,qBAAC,MAAD;GACE,WAAW,GAAG,cAAc,OAAO,WAAW,SAAS;GACvD,iBAAe;GACf,GAAI;GAHN,UAAA;KAKI,YAAY,QAAQ,aACpB,KAAK,OAAO,OAAO;KACjB,WAAW;KACX,UACE,qBAAA,YAAA,EAAA,UAAA,CACG,KAAK,YAAY,QAAQ;MACxB,WAAW;MACX,UAAU;KACZ,CAAC,GACA,YACC,KAAK,QAAQ,QAAQ;MACnB,WAAW;MACX,MAAM;MACN,OAAO,SAAS,OAAO,SAAS,OAAO;MACvC,eAAe,UAAU,KAAA;MACzB,eACE,KAAK,KAAK,QAAQ,SAAS,eAAe,MAAM,CAAC,EAAE,eAAe,EAAE;MACtE,UAAU,SAAS,oBAAC,WAAD,EAAW,MAAM,GAAK,CAAA,IAAI,oBAAC,UAAD,EAAU,MAAM,GAAK,CAAA;KACpE,CAAC,CACH,EAAA,CAAA;IAEN,CAAC;IACF,KAAK,OAAO,OAAO;KAClB,IAAI;KACJ,WAAW;KACX,UAAU;KAEV,MAAM;KACN,cAAc;KACd,UAAU;IACZ,CAAC;IACA,YACC,oBAAC,QAAD;KAAM,WAAU;KAAwB,MAAK;KAC1C,UAAA,SAAS,OAAO,SAAS;IACtB,CAAA;GAEJ;;CACN,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
import { PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType, ReactNode } from "react";
|
|
4
|
+
export interface CompareLabels {
|
|
5
|
+
/** Names the slider: how much of the "after" shows. */
|
|
6
|
+
handle: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const COMPARE_LABELS: CompareLabels;
|
|
9
|
+
export interface CompareOwnProps {
|
|
10
|
+
/** The "before" content (usually an image), on the start side. */
|
|
11
|
+
before: ReactNode;
|
|
12
|
+
/** The "after" content, same size as `before`. */
|
|
13
|
+
after: ReactNode;
|
|
14
|
+
/** Share of the width given to `before`, 0–100. Default 50. */
|
|
15
|
+
value?: number;
|
|
16
|
+
defaultValue?: number;
|
|
17
|
+
onValueChange?: (value: number) => void;
|
|
18
|
+
labels?: Partial<CompareLabels>;
|
|
19
|
+
}
|
|
20
|
+
export type CompareProps<E extends ElementType = 'div'> = PolymorphicProps<E, CompareOwnProps>;
|
|
21
|
+
/** Two pictures in one frame with a divider that sweeps between them: a range input, so keys and touch just work. */
|
|
22
|
+
export declare function Compare<E extends ElementType = 'div'>(props: CompareProps<E>): import("react").JSX.Element;
|
|
23
|
+
//# sourceMappingURL=Compare.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
3
|
+
import { cx } from "../utils/src/index.js";
|
|
4
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
5
|
+
import { useCss, useThemeProps } from "../internal/styled.js";
|
|
6
|
+
import { useControlled } from "../utils/useControlled.js";
|
|
7
|
+
import { useId } from "react";
|
|
8
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
// src/Compare/Compare.tsx
|
|
10
|
+
const COMPARE_LABELS = { handle: "Confronta prima e dopo" };
|
|
11
|
+
/** Two pictures in one frame with a divider that sweeps between them: a range input, so keys and touch just work. */
|
|
12
|
+
function Compare(props) {
|
|
13
|
+
const { as, css, className, before, after, value: valueProp, defaultValue = 50, onValueChange, labels: labelsProp, ...rest } = useThemeProps("Compare", props);
|
|
14
|
+
const labels = {
|
|
15
|
+
...COMPARE_LABELS,
|
|
16
|
+
...useLabels("Compare"),
|
|
17
|
+
...labelsProp
|
|
18
|
+
};
|
|
19
|
+
const [value, setValue] = useControlled({
|
|
20
|
+
value: valueProp,
|
|
21
|
+
defaultValue,
|
|
22
|
+
onChange: onValueChange
|
|
23
|
+
});
|
|
24
|
+
const Root = as ?? "div";
|
|
25
|
+
const styled = useCss("Compare", "root", css);
|
|
26
|
+
const root = useAnimationRoot(rest);
|
|
27
|
+
const id = useId();
|
|
28
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [styled.style, /* @__PURE__ */ jsxs(Root, {
|
|
29
|
+
className: cx("slurp-compare", styled.className, className),
|
|
30
|
+
style: { "--slurp-compare": `${value}%` },
|
|
31
|
+
...root,
|
|
32
|
+
children: [
|
|
33
|
+
/* @__PURE__ */ jsx("div", {
|
|
34
|
+
className: "slurp-compare-after",
|
|
35
|
+
children: after
|
|
36
|
+
}),
|
|
37
|
+
/* @__PURE__ */ jsx("div", {
|
|
38
|
+
className: "slurp-compare-before",
|
|
39
|
+
children: before
|
|
40
|
+
}),
|
|
41
|
+
/* @__PURE__ */ jsx("span", {
|
|
42
|
+
className: "slurp-compare-line",
|
|
43
|
+
"aria-hidden": "true"
|
|
44
|
+
}),
|
|
45
|
+
/* @__PURE__ */ jsx("input", {
|
|
46
|
+
id,
|
|
47
|
+
type: "range",
|
|
48
|
+
min: 0,
|
|
49
|
+
max: 100,
|
|
50
|
+
value,
|
|
51
|
+
"aria-label": labels.handle,
|
|
52
|
+
"aria-valuetext": `${Math.round(value)}%`,
|
|
53
|
+
className: "slurp-compare-range",
|
|
54
|
+
onChange: (e) => setValue(Number(e.target.value))
|
|
55
|
+
})
|
|
56
|
+
]
|
|
57
|
+
})] });
|
|
58
|
+
}
|
|
59
|
+
export { COMPARE_LABELS, Compare };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=Compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Compare.js","names":[],"sources":["../../src/Compare/Compare.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport {\n useId,\n type ChangeEvent,\n type CSSProperties,\n type ElementType,\n type ReactNode,\n} from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useLabels } from '../internal/labels';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\nimport { useControlled } from '../utils/useControlled';\n\nexport interface CompareLabels {\n /** Names the slider: how much of the \"after\" shows. */\n handle: string;\n}\n\nexport const COMPARE_LABELS: CompareLabels = { handle: 'Confronta prima e dopo' };\n\nexport interface CompareOwnProps {\n /** The \"before\" content (usually an image), on the start side. */\n before: ReactNode;\n /** The \"after\" content, same size as `before`. */\n after: ReactNode;\n /** Share of the width given to `before`, 0–100. Default 50. */\n value?: number;\n defaultValue?: number;\n onValueChange?: (value: number) => void;\n labels?: Partial<CompareLabels>;\n}\n\nexport type CompareProps<E extends ElementType = 'div'> = PolymorphicProps<E, CompareOwnProps>;\n\n/** Two pictures in one frame with a divider that sweeps between them: a range input, so keys and touch just work. */\nexport function Compare<E extends ElementType = 'div'>(props: CompareProps<E>) {\n const {\n as,\n css,\n className,\n before,\n after,\n value: valueProp,\n defaultValue = 50,\n onValueChange,\n labels: labelsProp,\n ...rest\n } = useThemeProps('Compare', props as CompareProps);\n const labels = { ...COMPARE_LABELS, ...useLabels('Compare'), ...labelsProp };\n const [value, setValue] = useControlled({\n value: valueProp,\n defaultValue,\n onChange: onValueChange,\n });\n const Root = (as ?? 'div') as ElementType;\n const styled = useCss('Compare', 'root', css);\n const root = useAnimationRoot(rest);\n const id = useId();\n return (\n <>\n {styled.style}\n <Root\n className={cx('slurp-compare', styled.className, className)}\n style={{ '--slurp-compare': `${value}%` } as CSSProperties}\n {...root}\n >\n <div className=\"slurp-compare-after\">{after}</div>\n <div className=\"slurp-compare-before\">{before}</div>\n <span className=\"slurp-compare-line\" aria-hidden=\"true\" />\n <input\n id={id}\n type=\"range\"\n min={0}\n max={100}\n value={value}\n aria-label={labels.handle}\n aria-valuetext={`${Math.round(value)}%`}\n className=\"slurp-compare-range\"\n onChange={(e: ChangeEvent<HTMLInputElement>) => setValue(Number(e.target.value))}\n />\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;AAoBA,MAAa,iBAAgC,EAAE,QAAQ,yBAAyB;;AAiBhF,SAAgB,QAAuC,OAAwB;CAC7E,MAAM,EACJ,IACA,KACA,WACA,QACA,OACA,OAAO,WACP,eAAe,IACf,eACA,QAAQ,YACR,GAAG,SACD,cAAc,WAAW,KAAqB;CAClD,MAAM,SAAS;EAAE,GAAG;EAAgB,GAAG,UAAU,SAAS;EAAG,GAAG;CAAW;CAC3E,MAAM,CAAC,OAAO,YAAY,cAAc;EACtC,OAAO;EACP;EACA,UAAU;CACZ,CAAC;CACD,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,WAAW,QAAQ,GAAG;CAC5C,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,KAAK,MAAM;CACjB,OACE,qBAAA,YAAA,EAAA,UAAA,CACG,OAAO,OACR,qBAAC,MAAD;EACE,WAAW,GAAG,iBAAiB,OAAO,WAAW,SAAS;EAC1D,OAAO,EAAE,mBAAmB,GAAG,MAAM,GAAG;EACxC,GAAI;EAHN,UAAA;GAKE,oBAAC,OAAD;IAAK,WAAU;IAAuB,UAAA;GAAW,CAAA;GACjD,oBAAC,OAAD;IAAK,WAAU;IAAwB,UAAA;GAAY,CAAA;GACnD,oBAAC,QAAD;IAAM,WAAU;IAAqB,eAAY;GAAQ,CAAA;GACzD,oBAAC,SAAD;IACM;IACJ,MAAK;IACL,KAAK;IACL,KAAK;IACE;IACP,cAAY,OAAO;IACnB,kBAAgB,GAAG,KAAK,MAAM,KAAK,EAAE;IACrC,WAAU;IACV,WAAW,MAAqC,SAAS,OAAO,EAAE,OAAO,KAAK,CAAC;GAChF,CAAA;EACG;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
import { PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType, ReactNode } from "react";
|
|
4
|
+
export interface ConsentLabels {
|
|
5
|
+
/** Names the banner's region. */
|
|
6
|
+
region: string;
|
|
7
|
+
accept: string;
|
|
8
|
+
reject: string;
|
|
9
|
+
customize: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const CONSENT_LABELS: ConsentLabels;
|
|
12
|
+
export interface ConsentOwnProps {
|
|
13
|
+
/** Shown or not: the app keeps the choice (and decides when to ask again). Default true. */
|
|
14
|
+
open?: boolean;
|
|
15
|
+
title?: ReactNode;
|
|
16
|
+
onAccept?: () => void;
|
|
17
|
+
onReject?: () => void;
|
|
18
|
+
/** Adds a "Personalizza" button, for a settings dialog. */
|
|
19
|
+
onCustomize?: () => void;
|
|
20
|
+
labels?: Partial<ConsentLabels>;
|
|
21
|
+
/** What is asked and why: link the policy here. */
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
export type ConsentProps<E extends ElementType = 'section'> = PolymorphicProps<E, ConsentOwnProps>;
|
|
25
|
+
/**
|
|
26
|
+
* A consent banner fixed to the bottom of the page. Accepting and rejecting are the same size and weight: refusing
|
|
27
|
+
* is as easy as agreeing. It does not trap focus or block the page; the app stores the answer.
|
|
28
|
+
*/
|
|
29
|
+
export declare function Consent<E extends ElementType = 'section'>(props: ConsentProps<E>): import("react").JSX.Element | null;
|
|
30
|
+
//# sourceMappingURL=Consent.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
3
|
+
import { cx } from "../utils/src/index.js";
|
|
4
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
5
|
+
import { useCss, useThemeProps } from "../internal/styled.js";
|
|
6
|
+
import { Button } from "../Button/Button.js";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
// src/Consent/Consent.tsx
|
|
9
|
+
const CONSENT_LABELS = {
|
|
10
|
+
region: "Preferenze sui cookie",
|
|
11
|
+
accept: "Accetta",
|
|
12
|
+
reject: "Rifiuta",
|
|
13
|
+
customize: "Personalizza"
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A consent banner fixed to the bottom of the page. Accepting and rejecting are the same size and weight: refusing
|
|
17
|
+
* is as easy as agreeing. It does not trap focus or block the page; the app stores the answer.
|
|
18
|
+
*/
|
|
19
|
+
function Consent(props) {
|
|
20
|
+
const { as, css, className, open = true, title, onAccept, onReject, onCustomize, labels: labelsProp, children, ...rest } = useThemeProps("Consent", props);
|
|
21
|
+
const labels = {
|
|
22
|
+
...CONSENT_LABELS,
|
|
23
|
+
...useLabels("Consent"),
|
|
24
|
+
...labelsProp
|
|
25
|
+
};
|
|
26
|
+
const Root = as ?? "section";
|
|
27
|
+
const styled = useCss("Consent", "root", css);
|
|
28
|
+
const root = useAnimationRoot(rest);
|
|
29
|
+
if (!open) return null;
|
|
30
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [styled.style, /* @__PURE__ */ jsxs(Root, {
|
|
31
|
+
"aria-label": labels.region,
|
|
32
|
+
className: cx("slurp-consent", styled.className, className),
|
|
33
|
+
...root,
|
|
34
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
35
|
+
className: "slurp-consent-text",
|
|
36
|
+
children: [title != null && /* @__PURE__ */ jsx("p", {
|
|
37
|
+
className: "slurp-consent-title",
|
|
38
|
+
children: title
|
|
39
|
+
}), children != null && /* @__PURE__ */ jsx("div", {
|
|
40
|
+
className: "slurp-consent-body",
|
|
41
|
+
children
|
|
42
|
+
})]
|
|
43
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
44
|
+
className: "slurp-consent-actions",
|
|
45
|
+
children: [
|
|
46
|
+
/* @__PURE__ */ jsx(Button, {
|
|
47
|
+
tone: "neutral",
|
|
48
|
+
size: "sm",
|
|
49
|
+
onClick: onReject,
|
|
50
|
+
children: labels.reject
|
|
51
|
+
}),
|
|
52
|
+
onCustomize && /* @__PURE__ */ jsx(Button, {
|
|
53
|
+
tone: "neutral",
|
|
54
|
+
size: "sm",
|
|
55
|
+
onClick: onCustomize,
|
|
56
|
+
children: labels.customize
|
|
57
|
+
}),
|
|
58
|
+
/* @__PURE__ */ jsx(Button, {
|
|
59
|
+
tone: "accent",
|
|
60
|
+
size: "sm",
|
|
61
|
+
onClick: onAccept,
|
|
62
|
+
children: labels.accept
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
})]
|
|
66
|
+
})] });
|
|
67
|
+
}
|
|
68
|
+
export { CONSENT_LABELS, Consent };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=Consent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Consent.js","names":[],"sources":["../../src/Consent/Consent.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport type { ElementType, ReactNode } from 'react';\n\nimport { Button } from '../Button/Button';\nimport { useAnimationRoot } from '../internal/animation';\nimport { useLabels } from '../internal/labels';\nimport { useCss, useThemeProps } from '../internal/styled';\nimport type { PolymorphicProps } from '../lib/polymorphic';\n\nexport interface ConsentLabels {\n /** Names the banner's region. */\n region: string;\n accept: string;\n reject: string;\n customize: string;\n}\n\nexport const CONSENT_LABELS: ConsentLabels = {\n region: 'Preferenze sui cookie',\n accept: 'Accetta',\n reject: 'Rifiuta',\n customize: 'Personalizza',\n};\n\nexport interface ConsentOwnProps {\n /** Shown or not: the app keeps the choice (and decides when to ask again). Default true. */\n open?: boolean;\n title?: ReactNode;\n onAccept?: () => void;\n onReject?: () => void;\n /** Adds a \"Personalizza\" button, for a settings dialog. */\n onCustomize?: () => void;\n labels?: Partial<ConsentLabels>;\n /** What is asked and why: link the policy here. */\n children?: ReactNode;\n}\n\nexport type ConsentProps<E extends ElementType = 'section'> = PolymorphicProps<E, ConsentOwnProps>;\n\n/**\n * A consent banner fixed to the bottom of the page. Accepting and rejecting are the same size and weight: refusing\n * is as easy as agreeing. It does not trap focus or block the page; the app stores the answer.\n */\nexport function Consent<E extends ElementType = 'section'>(props: ConsentProps<E>) {\n const {\n as,\n css,\n className,\n open = true,\n title,\n onAccept,\n onReject,\n onCustomize,\n labels: labelsProp,\n children,\n ...rest\n } = useThemeProps('Consent', props as ConsentProps);\n const labels = { ...CONSENT_LABELS, ...useLabels('Consent'), ...labelsProp };\n const Root = (as ?? 'section') as ElementType;\n const styled = useCss('Consent', 'root', css);\n const root = useAnimationRoot(rest);\n if (!open) return null;\n return (\n <>\n {styled.style}\n <Root\n aria-label={labels.region}\n className={cx('slurp-consent', styled.className, className)}\n {...root}\n >\n <div className=\"slurp-consent-text\">\n {title != null && <p className=\"slurp-consent-title\">{title}</p>}\n {children != null && <div className=\"slurp-consent-body\">{children}</div>}\n </div>\n <div className=\"slurp-consent-actions\">\n <Button tone=\"neutral\" size=\"sm\" onClick={onReject}>\n {labels.reject}\n </Button>\n {onCustomize && (\n <Button tone=\"neutral\" size=\"sm\" onClick={onCustomize}>\n {labels.customize}\n </Button>\n )}\n <Button tone=\"accent\" size=\"sm\" onClick={onAccept}>\n {labels.accept}\n </Button>\n </div>\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;AAiBA,MAAa,iBAAgC;CAC3C,QAAQ;CACR,QAAQ;CACR,QAAQ;CACR,WAAW;AACb;;;;;AAqBA,SAAgB,QAA2C,OAAwB;CACjF,MAAM,EACJ,IACA,KACA,WACA,OAAO,MACP,OACA,UACA,UACA,aACA,QAAQ,YACR,UACA,GAAG,SACD,cAAc,WAAW,KAAqB;CAClD,MAAM,SAAS;EAAE,GAAG;EAAgB,GAAG,UAAU,SAAS;EAAG,GAAG;CAAW;CAC3E,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,WAAW,QAAQ,GAAG;CAC5C,MAAM,OAAO,iBAAiB,IAAI;CAClC,IAAI,CAAC,MAAM,OAAO;CAClB,OACE,qBAAA,UAAA,EAAA,UAAA,CACG,OAAO,OACR,qBAAC,MAAD;EACE,cAAY,OAAO;EACnB,WAAW,GAAG,iBAAiB,OAAO,WAAW,SAAS;EAC1D,GAAI;EAHN,UAAA,CAKE,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACG,SAAS,QAAQ,oBAAC,KAAD;IAAG,WAAU;IAAuB,UAAA;GAAS,CAAA,GAC9D,YAAY,QAAQ,oBAAC,OAAD;IAAK,WAAU;IAAsB;GAAc,CAAA,CACrE;EACL,CAAA,GAAA,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IACE,oBAAC,QAAD;KAAQ,MAAK;KAAU,MAAK;KAAK,SAAS;KACvC,UAAA,OAAO;IACF,CAAA;IACP,eACC,oBAAC,QAAD;KAAQ,MAAK;KAAU,MAAK;KAAK,SAAS;KACvC,UAAA,OAAO;IACF,CAAA;IAEV,oBAAC,QAAD;KAAQ,MAAK;KAAS,MAAK;KAAK,SAAS;KACtC,UAAA,OAAO;IACF,CAAA;GACL;EACD,CAAA,CAAA;CACN,CAAA,CAAA,EAAA,CAAA;AAEN"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
import { PartsProps, PolymorphicProps } from "../lib/polymorphic.js";
|
|
3
|
+
import { ElementType, ReactNode } from "react";
|
|
4
|
+
export interface ContentsLabels {
|
|
5
|
+
/** The visible title and the name of the navigation. */
|
|
6
|
+
title: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const CONTENTS_LABELS: ContentsLabels;
|
|
9
|
+
export interface ContentsItem {
|
|
10
|
+
/** Id of the heading (the link goes to `#id`). */
|
|
11
|
+
id: string;
|
|
12
|
+
label: ReactNode;
|
|
13
|
+
/** 2 (default) or 3: a level-3 item is indented under its section. */
|
|
14
|
+
level?: 2 | 3;
|
|
15
|
+
}
|
|
16
|
+
export interface ContentsOwnProps extends PartsProps<'title' | 'list' | 'item' | 'link'> {
|
|
17
|
+
items: readonly ContentsItem[];
|
|
18
|
+
/**
|
|
19
|
+
* The section being read. Leave it out to follow the scroll (`useScrollSpy`); pass it to drive it yourself (`null`
|
|
20
|
+
* for none).
|
|
21
|
+
*/
|
|
22
|
+
active?: string | null;
|
|
23
|
+
/** Hide the visible title (the navigation keeps its name). */
|
|
24
|
+
hideTitle?: boolean;
|
|
25
|
+
/** Called when a link is followed (e.g. to close the panel it sits in). */
|
|
26
|
+
onNavigate?: (id: string) => void;
|
|
27
|
+
labels?: Partial<ContentsLabels>;
|
|
28
|
+
}
|
|
29
|
+
export type ContentsProps<E extends ElementType = 'nav'> = PolymorphicProps<E, ContentsOwnProps>;
|
|
30
|
+
/**
|
|
31
|
+
* "On this page": links to a page's sections, the one being read highlighted like a ListRow (accent-soft with an
|
|
32
|
+
* accent-ink outline) and marked `aria-current="location"`. Hidden with fewer than two items.
|
|
33
|
+
*/
|
|
34
|
+
export declare function Contents<E extends ElementType = 'nav'>(props: ContentsProps<E>): import("react").JSX.Element | null;
|
|
35
|
+
//# sourceMappingURL=Contents.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLabels } from "../internal/labels.js";
|
|
3
|
+
import { cx } from "../utils/src/index.js";
|
|
4
|
+
import { useAnimationRoot } from "../internal/animation.js";
|
|
5
|
+
import { useCss, useParts, useThemeProps } from "../internal/styled.js";
|
|
6
|
+
import { useScrollSpy } from "../utils/useScrollSpy.js";
|
|
7
|
+
import { Fragment } from "react";
|
|
8
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
// src/Contents/Contents.tsx
|
|
10
|
+
const CONTENTS_LABELS = { title: "In questa pagina" };
|
|
11
|
+
/**
|
|
12
|
+
* "On this page": links to a page's sections, the one being read highlighted like a ListRow (accent-soft with an
|
|
13
|
+
* accent-ink outline) and marked `aria-current="location"`. Hidden with fewer than two items.
|
|
14
|
+
*/
|
|
15
|
+
function Contents(props) {
|
|
16
|
+
const { as, css, className, items, active: activeProp, hideTitle = false, onNavigate, labels: labelsProp, parts, partProps, classNames, ...rest } = useThemeProps("Contents", props);
|
|
17
|
+
const labels = {
|
|
18
|
+
...CONTENTS_LABELS,
|
|
19
|
+
...useLabels("Contents"),
|
|
20
|
+
...labelsProp
|
|
21
|
+
};
|
|
22
|
+
const Root = as ?? "nav";
|
|
23
|
+
const styled = useCss("Contents", "root", css);
|
|
24
|
+
const { part, style } = useParts("Contents", {
|
|
25
|
+
parts,
|
|
26
|
+
partProps,
|
|
27
|
+
classNames
|
|
28
|
+
});
|
|
29
|
+
const root = useAnimationRoot(rest);
|
|
30
|
+
const spied = useScrollSpy(activeProp === void 0 ? items.map((i) => i.id) : []);
|
|
31
|
+
const active = activeProp === void 0 ? spied : activeProp;
|
|
32
|
+
if (items.length < 2) return null;
|
|
33
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
34
|
+
styled.style,
|
|
35
|
+
style,
|
|
36
|
+
/* @__PURE__ */ jsxs(Root, {
|
|
37
|
+
className: cx("slurp-contents", styled.className, className),
|
|
38
|
+
"aria-label": labels.title,
|
|
39
|
+
...root,
|
|
40
|
+
children: [!hideTitle && part("title", "p", {
|
|
41
|
+
className: "slurp-contents-title",
|
|
42
|
+
"aria-hidden": true,
|
|
43
|
+
children: labels.title
|
|
44
|
+
}), part("list", "ul", {
|
|
45
|
+
className: "slurp-contents-list",
|
|
46
|
+
children: items.map((item) => /* @__PURE__ */ jsx(Fragment, { children: part("item", "li", {
|
|
47
|
+
className: "slurp-contents-item",
|
|
48
|
+
"data-level": item.level ?? 2,
|
|
49
|
+
children: part("link", "a", {
|
|
50
|
+
className: "slurp-contents-link",
|
|
51
|
+
href: `#${item.id}`,
|
|
52
|
+
"aria-current": item.id === active ? "location" : void 0,
|
|
53
|
+
onClick: () => onNavigate?.(item.id),
|
|
54
|
+
children: item.label
|
|
55
|
+
})
|
|
56
|
+
}) }, item.id))
|
|
57
|
+
})]
|
|
58
|
+
})
|
|
59
|
+
] });
|
|
60
|
+
}
|
|
61
|
+
export { CONTENTS_LABELS, Contents };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=Contents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Contents.js","names":[],"sources":["../../src/Contents/Contents.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport { Fragment, type ElementType, type ReactNode } from 'react';\n\nimport { useAnimationRoot } from '../internal/animation';\nimport { useLabels } from '../internal/labels';\nimport { useCss, useParts, useThemeProps } from '../internal/styled';\nimport type { PartsProps, PolymorphicProps } from '../lib/polymorphic';\nimport { useScrollSpy } from '../utils/useScrollSpy';\n\nexport interface ContentsLabels {\n /** The visible title and the name of the navigation. */\n title: string;\n}\n\nexport const CONTENTS_LABELS: ContentsLabels = { title: 'In questa pagina' };\n\nexport interface ContentsItem {\n /** Id of the heading (the link goes to `#id`). */\n id: string;\n label: ReactNode;\n /** 2 (default) or 3: a level-3 item is indented under its section. */\n level?: 2 | 3;\n}\n\nexport interface ContentsOwnProps extends PartsProps<'title' | 'list' | 'item' | 'link'> {\n items: readonly ContentsItem[];\n /**\n * The section being read. Leave it out to follow the scroll (`useScrollSpy`); pass it to drive it yourself (`null`\n * for none).\n */\n active?: string | null;\n /** Hide the visible title (the navigation keeps its name). */\n hideTitle?: boolean;\n /** Called when a link is followed (e.g. to close the panel it sits in). */\n onNavigate?: (id: string) => void;\n labels?: Partial<ContentsLabels>;\n}\n\nexport type ContentsProps<E extends ElementType = 'nav'> = PolymorphicProps<E, ContentsOwnProps>;\n\n/**\n * \"On this page\": links to a page's sections, the one being read highlighted like a ListRow (accent-soft with an\n * accent-ink outline) and marked `aria-current=\"location\"`. Hidden with fewer than two items.\n */\nexport function Contents<E extends ElementType = 'nav'>(props: ContentsProps<E>) {\n const {\n as,\n css,\n className,\n items,\n active: activeProp,\n hideTitle = false,\n onNavigate,\n labels: labelsProp,\n parts,\n partProps,\n classNames,\n ...rest\n } = useThemeProps('Contents', props as ContentsProps);\n const labels = { ...CONTENTS_LABELS, ...useLabels('Contents'), ...labelsProp };\n const Root = (as ?? 'nav') as ElementType;\n const styled = useCss('Contents', 'root', css);\n const { part, style } = useParts('Contents', { parts, partProps, classNames });\n const root = useAnimationRoot(rest);\n const spied = useScrollSpy(activeProp === undefined ? items.map((i) => i.id) : []);\n const active = activeProp === undefined ? spied : activeProp;\n\n if (items.length < 2) return null;\n return (\n <>\n {styled.style}\n {style}\n <Root\n className={cx('slurp-contents', styled.className, className)}\n aria-label={labels.title}\n {...root}\n >\n {!hideTitle &&\n part('title', 'p', {\n className: 'slurp-contents-title',\n 'aria-hidden': true,\n children: labels.title,\n })}\n {part('list', 'ul', {\n className: 'slurp-contents-list',\n children: items.map((item) => (\n <Fragment key={item.id}>\n {part('item', 'li', {\n className: 'slurp-contents-item',\n 'data-level': item.level ?? 2,\n children: part('link', 'a', {\n className: 'slurp-contents-link',\n href: `#${item.id}`,\n 'aria-current': item.id === active ? 'location' : undefined,\n onClick: () => onNavigate?.(item.id),\n children: item.label,\n }),\n })}\n </Fragment>\n )),\n })}\n </Root>\n </>\n );\n}\n"],"mappings":";;;;;;;;;AAcA,MAAa,kBAAkC,EAAE,OAAO,mBAAmB;;;;;AA8B3E,SAAgB,SAAwC,OAAyB;CAC/E,MAAM,EACJ,IACA,KACA,WACA,OACA,QAAQ,YACR,YAAY,OACZ,YACA,QAAQ,YACR,OACA,WACA,YACA,GAAG,SACD,cAAc,YAAY,KAAsB;CACpD,MAAM,SAAS;EAAE,GAAG;EAAiB,GAAG,UAAU,UAAU;EAAG,GAAG;CAAW;CAC7E,MAAM,OAAQ,MAAM;CACpB,MAAM,SAAS,OAAO,YAAY,QAAQ,GAAG;CAC7C,MAAM,EAAE,MAAM,UAAU,SAAS,YAAY;EAAE;EAAO;EAAW;CAAW,CAAC;CAC7E,MAAM,OAAO,iBAAiB,IAAI;CAClC,MAAM,QAAQ,aAAa,eAAe,KAAA,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