@central-ui/react 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +31 -2
- package/dist/components/accordion/index.d.ts +73 -0
- package/dist/components/accordion/index.d.ts.map +1 -0
- package/dist/components/accordion/index.js +92 -0
- package/dist/components/accordion/index.js.map +1 -0
- package/dist/components/autocomplete/index.d.ts +365 -0
- package/dist/components/autocomplete/index.d.ts.map +1 -0
- package/dist/components/autocomplete/index.js +369 -0
- package/dist/components/autocomplete/index.js.map +1 -0
- package/dist/components/avatar/index.d.ts +48 -0
- package/dist/components/avatar/index.d.ts.map +1 -0
- package/dist/components/avatar/index.js +60 -0
- package/dist/components/avatar/index.js.map +1 -0
- package/dist/components/badge/index.d.ts +29 -0
- package/dist/components/badge/index.d.ts.map +1 -0
- package/dist/components/badge/index.js +36 -0
- package/dist/components/badge/index.js.map +1 -0
- package/dist/components/banner/index.d.ts +71 -0
- package/dist/components/banner/index.d.ts.map +1 -0
- package/dist/components/banner/index.js +119 -0
- package/dist/components/banner/index.js.map +1 -0
- package/dist/components/breadcrumb/index.d.ts +31 -0
- package/dist/components/breadcrumb/index.d.ts.map +1 -0
- package/dist/components/breadcrumb/index.js +42 -0
- package/dist/components/breadcrumb/index.js.map +1 -0
- package/dist/components/button/index.d.ts +48 -0
- package/dist/components/button/index.d.ts.map +1 -0
- package/dist/components/button/index.js +60 -0
- package/dist/components/button/index.js.map +1 -0
- package/dist/components/card/index.d.ts +34 -0
- package/dist/components/card/index.d.ts.map +1 -0
- package/dist/components/card/index.js +45 -0
- package/dist/components/card/index.js.map +1 -0
- package/dist/components/checkbox/index.d.ts +66 -0
- package/dist/components/checkbox/index.d.ts.map +1 -0
- package/dist/components/checkbox/index.js +146 -0
- package/dist/components/checkbox/index.js.map +1 -0
- package/dist/components/chip/index.d.ts +26 -0
- package/dist/components/chip/index.d.ts.map +1 -0
- package/dist/components/chip/index.js +40 -0
- package/dist/components/chip/index.js.map +1 -0
- package/dist/components/combobox/index.d.ts +427 -0
- package/dist/components/combobox/index.d.ts.map +1 -0
- package/dist/components/combobox/index.js +416 -0
- package/dist/components/combobox/index.js.map +1 -0
- package/dist/components/datepicker/index.d.ts +297 -0
- package/dist/components/datepicker/index.d.ts.map +1 -0
- package/dist/components/datepicker/index.js +507 -0
- package/dist/components/datepicker/index.js.map +1 -0
- package/dist/components/dialog/index.d.ts +88 -0
- package/dist/components/dialog/index.d.ts.map +1 -0
- package/dist/components/dialog/index.js +102 -0
- package/dist/components/dialog/index.js.map +1 -0
- package/dist/components/divider/index.d.ts +21 -0
- package/dist/components/divider/index.d.ts.map +1 -0
- package/dist/components/divider/index.js +24 -0
- package/dist/components/divider/index.js.map +1 -0
- package/dist/components/drawer/index.d.ts +99 -0
- package/dist/components/drawer/index.d.ts.map +1 -0
- package/dist/components/drawer/index.js +137 -0
- package/dist/components/drawer/index.js.map +1 -0
- package/dist/components/empty/index.d.ts +40 -0
- package/dist/components/empty/index.d.ts.map +1 -0
- package/dist/components/empty/index.js +61 -0
- package/dist/components/empty/index.js.map +1 -0
- package/dist/components/fileupload/index.d.ts +107 -0
- package/dist/components/fileupload/index.d.ts.map +1 -0
- package/dist/components/fileupload/index.js +185 -0
- package/dist/components/fileupload/index.js.map +1 -0
- package/dist/components/form/index.d.ts +34 -0
- package/dist/components/form/index.d.ts.map +1 -0
- package/dist/components/form/index.js +35 -0
- package/dist/components/form/index.js.map +1 -0
- package/dist/components/input/index.d.ts +85 -0
- package/dist/components/input/index.d.ts.map +1 -0
- package/dist/components/input/index.js +249 -0
- package/dist/components/input/index.js.map +1 -0
- package/dist/components/menu/index.d.ts +115 -0
- package/dist/components/menu/index.d.ts.map +1 -0
- package/dist/components/menu/index.js +188 -0
- package/dist/components/menu/index.js.map +1 -0
- package/dist/components/metric/index.d.ts +24 -0
- package/dist/components/metric/index.d.ts.map +1 -0
- package/dist/components/metric/index.js +26 -0
- package/dist/components/metric/index.js.map +1 -0
- package/dist/components/numberinput/index.d.ts +105 -0
- package/dist/components/numberinput/index.d.ts.map +1 -0
- package/dist/components/numberinput/index.js +240 -0
- package/dist/components/numberinput/index.js.map +1 -0
- package/dist/components/otpinput/index.d.ts +63 -0
- package/dist/components/otpinput/index.d.ts.map +1 -0
- package/dist/components/otpinput/index.js +133 -0
- package/dist/components/otpinput/index.js.map +1 -0
- package/dist/components/page/index.d.ts +54 -0
- package/dist/components/page/index.d.ts.map +1 -0
- package/dist/components/page/index.js +100 -0
- package/dist/components/page/index.js.map +1 -0
- package/dist/components/passwordinput/index.d.ts +88 -0
- package/dist/components/passwordinput/index.d.ts.map +1 -0
- package/dist/components/passwordinput/index.js +251 -0
- package/dist/components/passwordinput/index.js.map +1 -0
- package/dist/components/popover/index.d.ts +67 -0
- package/dist/components/popover/index.d.ts.map +1 -0
- package/dist/components/popover/index.js +76 -0
- package/dist/components/popover/index.js.map +1 -0
- package/dist/components/radio/index.d.ts +90 -0
- package/dist/components/radio/index.d.ts.map +1 -0
- package/dist/components/radio/index.js +232 -0
- package/dist/components/radio/index.js.map +1 -0
- package/dist/components/ratinginput/index.d.ts +59 -0
- package/dist/components/ratinginput/index.d.ts.map +1 -0
- package/dist/components/ratinginput/index.js +88 -0
- package/dist/components/ratinginput/index.js.map +1 -0
- package/dist/components/select/index.d.ts +205 -0
- package/dist/components/select/index.d.ts.map +1 -0
- package/dist/components/select/index.js +234 -0
- package/dist/components/select/index.js.map +1 -0
- package/dist/components/skeleton/index.d.ts +19 -0
- package/dist/components/skeleton/index.d.ts.map +1 -0
- package/dist/components/skeleton/index.js +20 -0
- package/dist/components/skeleton/index.js.map +1 -0
- package/dist/components/slider/index.d.ts +72 -0
- package/dist/components/slider/index.d.ts.map +1 -0
- package/dist/components/slider/index.js +159 -0
- package/dist/components/slider/index.js.map +1 -0
- package/dist/components/spinner/index.d.ts +14 -0
- package/dist/components/spinner/index.d.ts.map +1 -0
- package/dist/components/spinner/index.js +15 -0
- package/dist/components/spinner/index.js.map +1 -0
- package/dist/components/splitter/index.d.ts +49 -0
- package/dist/components/splitter/index.d.ts.map +1 -0
- package/dist/components/splitter/index.js +67 -0
- package/dist/components/splitter/index.js.map +1 -0
- package/dist/components/stepper/index.d.ts +82 -0
- package/dist/components/stepper/index.d.ts.map +1 -0
- package/dist/components/stepper/index.js +100 -0
- package/dist/components/stepper/index.js.map +1 -0
- package/dist/components/switch/index.d.ts +57 -0
- package/dist/components/switch/index.d.ts.map +1 -0
- package/dist/components/switch/index.js +101 -0
- package/dist/components/switch/index.js.map +1 -0
- package/dist/components/table/index.d.ts +110 -0
- package/dist/components/table/index.d.ts.map +1 -0
- package/dist/components/table/index.js +211 -0
- package/dist/components/table/index.js.map +1 -0
- package/dist/components/tabs/index.d.ts +67 -0
- package/dist/components/tabs/index.d.ts.map +1 -0
- package/dist/components/tabs/index.js +78 -0
- package/dist/components/tabs/index.js.map +1 -0
- package/dist/components/textarea/index.d.ts +72 -0
- package/dist/components/textarea/index.d.ts.map +1 -0
- package/dist/components/textarea/index.js +205 -0
- package/dist/components/textarea/index.js.map +1 -0
- package/dist/components/textlink/index.d.ts +39 -0
- package/dist/components/textlink/index.d.ts.map +1 -0
- package/dist/components/textlink/index.js +42 -0
- package/dist/components/textlink/index.js.map +1 -0
- package/dist/components/toast/index.d.ts +111 -0
- package/dist/components/toast/index.d.ts.map +1 -0
- package/dist/components/toast/index.js +205 -0
- package/dist/components/toast/index.js.map +1 -0
- package/dist/components/toggle/index.d.ts +41 -0
- package/dist/components/toggle/index.d.ts.map +1 -0
- package/dist/components/toggle/index.js +78 -0
- package/dist/components/toggle/index.js.map +1 -0
- package/dist/components/tooltip/index.d.ts +44 -0
- package/dist/components/tooltip/index.d.ts.map +1 -0
- package/dist/components/tooltip/index.js +51 -0
- package/dist/components/tooltip/index.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/types/Style.d.ts +14 -0
- package/dist/types/Style.d.ts.map +1 -0
- package/dist/types/Style.js +2 -0
- package/dist/types/Style.js.map +1 -0
- package/dist/types/Tone.d.ts +4 -0
- package/dist/types/Tone.d.ts.map +1 -0
- package/dist/types/Tone.js +2 -0
- package/dist/types/Tone.js.map +1 -0
- package/dist/utils/ArkStateToDataAttributes.d.ts +4 -0
- package/dist/utils/ArkStateToDataAttributes.d.ts.map +1 -0
- package/dist/utils/ArkStateToDataAttributes.js +9 -0
- package/dist/utils/ArkStateToDataAttributes.js.map +1 -0
- package/dist/utils/Tone.d.ts +3 -0
- package/dist/utils/Tone.d.ts.map +1 -0
- package/dist/utils/Tone.js +7 -0
- package/dist/utils/Tone.js.map +1 -0
- package/dist/utils/useForwardClickToInput.d.ts +4 -0
- package/dist/utils/useForwardClickToInput.d.ts.map +1 -0
- package/dist/utils/useForwardClickToInput.js +27 -0
- package/dist/utils/useForwardClickToInput.js.map +1 -0
- package/dist/utils/virtualization/useVirtualizedAutocomplete.d.ts +198 -0
- package/dist/utils/virtualization/useVirtualizedAutocomplete.d.ts.map +1 -0
- package/dist/utils/virtualization/useVirtualizedAutocomplete.js +180 -0
- package/dist/utils/virtualization/useVirtualizedAutocomplete.js.map +1 -0
- package/dist/utils/virtualization/useVirtualizedCombobox.d.ts +200 -0
- package/dist/utils/virtualization/useVirtualizedCombobox.d.ts.map +1 -0
- package/dist/utils/virtualization/useVirtualizedCombobox.js +174 -0
- package/dist/utils/virtualization/useVirtualizedCombobox.js.map +1 -0
- package/dist/utils/virtualization/useVirtualizedTable.d.ts +169 -0
- package/dist/utils/virtualization/useVirtualizedTable.d.ts.map +1 -0
- package/dist/utils/virtualization/useVirtualizedTable.js +127 -0
- package/dist/utils/virtualization/useVirtualizedTable.js.map +1 -0
- package/package.json +64 -4
- package/src/presets/shopify-polaris/shopify-polaris-accordion.css +28 -0
- package/src/presets/shopify-polaris/shopify-polaris-autocomplete.css +155 -0
- package/src/presets/shopify-polaris/shopify-polaris-avatar.css +47 -0
- package/src/presets/shopify-polaris/shopify-polaris-badge.css +27 -0
- package/src/presets/shopify-polaris/shopify-polaris-banner.css +111 -0
- package/src/presets/shopify-polaris/shopify-polaris-breadcrumb.css +16 -0
- package/src/presets/shopify-polaris/shopify-polaris-button.css +79 -0
- package/src/presets/shopify-polaris/shopify-polaris-card.css +28 -0
- package/src/presets/shopify-polaris/shopify-polaris-checkbox.css +52 -0
- package/src/presets/shopify-polaris/shopify-polaris-chip.css +16 -0
- package/src/presets/shopify-polaris/shopify-polaris-combobox.css +179 -0
- package/src/presets/shopify-polaris/shopify-polaris-datepicker.css +183 -0
- package/src/presets/shopify-polaris/shopify-polaris-dialog.css +40 -0
- package/src/presets/shopify-polaris/shopify-polaris-divider.css +12 -0
- package/src/presets/shopify-polaris/shopify-polaris-drawer.css +40 -0
- package/src/presets/shopify-polaris/shopify-polaris-empty.css +32 -0
- package/src/presets/shopify-polaris/shopify-polaris-fileupload.css +78 -0
- package/src/presets/shopify-polaris/shopify-polaris-form.css +8 -0
- package/src/presets/shopify-polaris/shopify-polaris-input.css +72 -0
- package/src/presets/shopify-polaris/shopify-polaris-menu.css +112 -0
- package/src/presets/shopify-polaris/shopify-polaris-metric.css +16 -0
- package/src/presets/shopify-polaris/shopify-polaris-numberinput.css +88 -0
- package/src/presets/shopify-polaris/shopify-polaris-otpinput.css +42 -0
- package/src/presets/shopify-polaris/shopify-polaris-page.css +69 -0
- package/src/presets/shopify-polaris/shopify-polaris-passwordinput.css +76 -0
- package/src/presets/shopify-polaris/shopify-polaris-popover.css +47 -0
- package/src/presets/shopify-polaris/shopify-polaris-radio.css +54 -0
- package/src/presets/shopify-polaris/shopify-polaris-ratinginput.css +42 -0
- package/src/presets/shopify-polaris/shopify-polaris-select.css +119 -0
- package/src/presets/shopify-polaris/shopify-polaris-skeleton.css +8 -0
- package/src/presets/shopify-polaris/shopify-polaris-slider.css +86 -0
- package/src/presets/shopify-polaris/shopify-polaris-spinner.css +16 -0
- package/src/presets/shopify-polaris/shopify-polaris-splitter.css +34 -0
- package/src/presets/shopify-polaris/shopify-polaris-stepper.css +55 -0
- package/src/presets/shopify-polaris/shopify-polaris-switch.css +38 -0
- package/src/presets/shopify-polaris/shopify-polaris-table.css +72 -0
- package/src/presets/shopify-polaris/shopify-polaris-tabs.css +33 -0
- package/src/presets/shopify-polaris/shopify-polaris-textarea.css +61 -0
- package/src/presets/shopify-polaris/shopify-polaris-textlink.css +8 -0
- package/src/presets/shopify-polaris/shopify-polaris-toggle.css +52 -0
- package/src/presets/shopify-polaris/shopify-polaris-tooltip.css +31 -0
- package/src/presets/shopify-polaris/shopify-polaris.css +380 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-accordion.css +28 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-autocomplete.css +155 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-avatar.css +47 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-badge.css +27 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-banner.css +96 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-breadcrumb.css +16 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-button.css +68 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-card.css +28 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-checkbox.css +52 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-chip.css +16 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-combobox.css +184 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-datepicker.css +187 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-dialog.css +40 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-divider.css +12 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-drawer.css +40 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-empty.css +32 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-fileupload.css +72 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-form.css +8 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-input.css +72 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-menu.css +112 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-metric.css +16 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-numberinput.css +88 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-otpinput.css +42 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-page.css +69 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-passwordinput.css +76 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-popover.css +47 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-radio.css +54 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-ratinginput.css +42 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-select.css +118 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-skeleton.css +8 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-slider.css +86 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-spinner.css +16 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-splitter.css +34 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-stepper.css +55 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-switch.css +38 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-table.css +72 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-tabs.css +33 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-textarea.css +61 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-textlink.css +8 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-toast.css +43 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-toggle.css +52 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy-tooltip.css +31 -0
- package/src/presets/shopify-polaris-legacy/shopify-polaris-legacy.css +381 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Input as BaseInput } from '@base-ui/react/input';
|
|
3
|
+
import { LoaderCircle } from 'lucide-react';
|
|
4
|
+
import { useRef } from 'react';
|
|
5
|
+
import { useForwardClickToInput } from "../../utils/useForwardClickToInput.js";
|
|
6
|
+
import { cloneElement, createContext, forwardRef, useContext, useEffect, useId, useState, } from 'react';
|
|
7
|
+
import { twMerge } from 'tailwind-merge';
|
|
8
|
+
import { ToneProvider, useToneContext } from "../../utils/Tone.js";
|
|
9
|
+
/**
|
|
10
|
+
* Keep value, name, and validation configuration on Root. Textarea is the editable control inside TextareaGroup. Optional Addon parts hold your supporting text or actions; they do not implement submission.
|
|
11
|
+
*
|
|
12
|
+
* @example Complete composition
|
|
13
|
+
* import { Textarea } from '@central-ui/react'
|
|
14
|
+
*
|
|
15
|
+
* function Example() {
|
|
16
|
+
* return (
|
|
17
|
+
* <Textarea.Root defaultValue="Hello" name="message">
|
|
18
|
+
* <Textarea.Container>
|
|
19
|
+
* <Textarea.Label>Message</Textarea.Label>
|
|
20
|
+
* <Textarea.TextareaGroup>
|
|
21
|
+
* <Textarea.Textarea rows={4} placeholder="Write your message" />
|
|
22
|
+
* </Textarea.TextareaGroup>
|
|
23
|
+
* <Textarea.Description>Enter your message.</Textarea.Description>
|
|
24
|
+
* </Textarea.Container>
|
|
25
|
+
* </Textarea.Root>
|
|
26
|
+
* )
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* @example Control the message from application state
|
|
30
|
+
* import { useState } from 'react'
|
|
31
|
+
* function ControlledExample() {
|
|
32
|
+
* const [value, setValue] = useState('')
|
|
33
|
+
* return (
|
|
34
|
+
* <Textarea.Root value={value} onValueChange={setValue}>
|
|
35
|
+
* {
|
|
36
|
+
* // Rest of components here
|
|
37
|
+
* }
|
|
38
|
+
* </Textarea.Root>
|
|
39
|
+
* )
|
|
40
|
+
* }
|
|
41
|
+
*/
|
|
42
|
+
export function Root({ children, id, tone = 'neutral', value, defaultValue, onValueChange, disabled = false, readOnly = false, required = false, ...coreProps }) {
|
|
43
|
+
const generatedId = useId();
|
|
44
|
+
const [valueInternalState, setValueInternalState] = useState(defaultValue ?? '');
|
|
45
|
+
const [connections, setConnections] = useState({
|
|
46
|
+
descriptionIds: [],
|
|
47
|
+
});
|
|
48
|
+
return (_jsx(InputContext.Provider, { value: {
|
|
49
|
+
inputId: id ?? generatedId,
|
|
50
|
+
disabled,
|
|
51
|
+
readOnly,
|
|
52
|
+
required,
|
|
53
|
+
value: value ?? valueInternalState,
|
|
54
|
+
setValueInternalState,
|
|
55
|
+
defaultValue,
|
|
56
|
+
controlled: value !== undefined,
|
|
57
|
+
onValueChange,
|
|
58
|
+
coreProps,
|
|
59
|
+
connections,
|
|
60
|
+
setConnections,
|
|
61
|
+
}, children: _jsx(ToneProvider, { value: tone, children: children }) }));
|
|
62
|
+
}
|
|
63
|
+
export const Textarea = forwardRef(function Textarea({ disableStyle, className, onChange, 'aria-describedby': describedBy, ...props }, ref) {
|
|
64
|
+
const context = useInputContext();
|
|
65
|
+
const tone = useToneContext();
|
|
66
|
+
const inputRef = useRef(null);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const form = inputRef.current?.form;
|
|
69
|
+
if (!form || context.controlled)
|
|
70
|
+
return;
|
|
71
|
+
const reset = (event) => {
|
|
72
|
+
queueMicrotask(() => {
|
|
73
|
+
if (!event.defaultPrevented)
|
|
74
|
+
context.setValueInternalState(context.defaultValue ?? '');
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
form.addEventListener('reset', reset);
|
|
78
|
+
return () => form.removeEventListener('reset', reset);
|
|
79
|
+
}, [
|
|
80
|
+
context.controlled,
|
|
81
|
+
context.defaultValue,
|
|
82
|
+
context.setValueInternalState,
|
|
83
|
+
context.coreProps.form,
|
|
84
|
+
]);
|
|
85
|
+
return (_jsx(BaseInput, { ...context.coreProps, render: _jsx("textarea", { ...props, onChange: onChange }), id: context.inputId, disabled: context.disabled, readOnly: context.readOnly, required: context.required, value: context.value, "data-tone": tone, "aria-invalid": tone === 'invalid' || props['aria-invalid'] || undefined, "aria-describedby": [describedBy, ...context.connections.descriptionIds]
|
|
86
|
+
.filter(Boolean)
|
|
87
|
+
.join(' ') || undefined, ref: (element) => {
|
|
88
|
+
inputRef.current = element;
|
|
89
|
+
if (typeof ref === 'function')
|
|
90
|
+
ref(inputRef.current);
|
|
91
|
+
else if (ref)
|
|
92
|
+
ref.current = inputRef.current;
|
|
93
|
+
}, onValueChange: (nextValue, details) => {
|
|
94
|
+
context.onValueChange?.(nextValue, details);
|
|
95
|
+
if (!details.isCanceled && !context.controlled)
|
|
96
|
+
context.setValueInternalState(nextValue);
|
|
97
|
+
}, "data-component": "textarea-textarea", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
98
|
+
});
|
|
99
|
+
export const TextareaGroup = forwardRef(function TextareaGroup({ disableStyle, className, onClick, ...props }, ref) {
|
|
100
|
+
const attributes = usePartAttributes();
|
|
101
|
+
const forwardClick = useForwardClickToInput('textarea', onClick);
|
|
102
|
+
return (_jsx("div", { ...attributes, ...props, ref: ref, onClick: forwardClick, "data-component": "textarea-textareagroup", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
103
|
+
});
|
|
104
|
+
export const Container = forwardRef(function Container({ disableStyle, className, ...props }, ref) {
|
|
105
|
+
const attributes = usePartAttributes();
|
|
106
|
+
return (_jsx("div", { ...attributes, ...props, ref: ref, "data-component": "textarea-container", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
107
|
+
});
|
|
108
|
+
/** Labels the associated control automatically. Supply the visible text; do not wire a second label association. */
|
|
109
|
+
export const Label = forwardRef(function Label({ disableStyle, className, id, ...props }, ref) {
|
|
110
|
+
const context = useInputContext();
|
|
111
|
+
const labelId = id ?? context.inputId + '-label';
|
|
112
|
+
const attributes = usePartAttributes();
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
context.setConnections((current) => ({ ...current, labelId }));
|
|
115
|
+
return () => context.setConnections((current) => ({
|
|
116
|
+
...current,
|
|
117
|
+
labelId: current.labelId === labelId ? undefined : current.labelId,
|
|
118
|
+
}));
|
|
119
|
+
}, [labelId, context.setConnections]);
|
|
120
|
+
return (_jsx("label", { ...attributes, ...props, id: labelId, ref: ref, htmlFor: context.inputId, "data-component": "textarea-label", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
121
|
+
});
|
|
122
|
+
export const Description = forwardRef(function Description({ disableStyle, className, id, ...props }, ref) {
|
|
123
|
+
const messageId = useMessageId(id);
|
|
124
|
+
const attributes = usePartAttributes();
|
|
125
|
+
return (_jsx("div", { ...attributes, ...props, id: messageId, ref: ref, "data-component": "textarea-description", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
126
|
+
});
|
|
127
|
+
/** You decide when to show this feedback. Changing tone does not validate data or render the message for you. */
|
|
128
|
+
export const Error = forwardRef(function Error({ disableStyle, className, id, ...props }, ref) {
|
|
129
|
+
const messageId = useMessageId(id);
|
|
130
|
+
const attributes = usePartAttributes();
|
|
131
|
+
return (_jsx("div", { role: "alert", "aria-atomic": "true", ...attributes, ...props, id: messageId, ref: ref, "data-component": "textarea-error", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
132
|
+
});
|
|
133
|
+
/** You decide when to show this feedback. Changing tone does not validate data or render the message for you. */
|
|
134
|
+
export const Success = forwardRef(function Success({ disableStyle, className, id, ...props }, ref) {
|
|
135
|
+
const messageId = useMessageId(id);
|
|
136
|
+
const attributes = usePartAttributes();
|
|
137
|
+
return (_jsx("div", { role: "status", "aria-atomic": "true", ...attributes, ...props, id: messageId, ref: ref, "data-component": "textarea-success", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
138
|
+
});
|
|
139
|
+
export const Addon = forwardRef(function Addon({ disableStyle, className, variant = 'normal', ...props }, ref) {
|
|
140
|
+
const attributes = usePartAttributes();
|
|
141
|
+
return (_jsx("div", { ...attributes, ...props, ref: ref, "data-variant": variant, "data-component": "textarea-addon", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
142
|
+
});
|
|
143
|
+
export const AddonText = forwardRef(function AddonText({ disableStyle, className, ...props }, ref) {
|
|
144
|
+
const attributes = usePartAttributes();
|
|
145
|
+
return (_jsx("span", { ...attributes, ...props, ref: ref, "data-component": "textarea-addontext", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
146
|
+
});
|
|
147
|
+
/** Supply the decorative icon as a child. Its classes are preserved; interaction belongs to the surrounding control. */
|
|
148
|
+
export function AddonIcon({ disableStyle, children, className, ...props }) {
|
|
149
|
+
const attributes = usePartAttributes();
|
|
150
|
+
return cloneElement(children, {
|
|
151
|
+
...attributes,
|
|
152
|
+
...props,
|
|
153
|
+
'aria-hidden': true,
|
|
154
|
+
strokeWidth: props.strokeWidth ?? children.props.strokeWidth ?? 1.5,
|
|
155
|
+
...{
|
|
156
|
+
'data-component': 'textarea-addonicon',
|
|
157
|
+
'data-style-disabled': disableStyle ? '' : undefined,
|
|
158
|
+
},
|
|
159
|
+
className: twMerge(children.props.className, className),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
export const AddonButton = forwardRef(function AddonButton({ disableStyle, className, disabled, type = 'button', ...props }, ref) {
|
|
163
|
+
const context = useInputContext();
|
|
164
|
+
const attributes = usePartAttributes();
|
|
165
|
+
return (_jsx("button", { ...attributes, ...props, ref: ref, type: type, disabled: disabled || context.disabled || context.readOnly, "data-component": "textarea-addonbutton", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
166
|
+
});
|
|
167
|
+
/** Built-in icon; no children needed. Use it inside its matching control. */
|
|
168
|
+
export const AddonLoadingIcon = forwardRef(function AddonLoadingIcon({ disableStyle, className, strokeWidth = 1.5, ...props }, ref) {
|
|
169
|
+
const attributes = usePartAttributes();
|
|
170
|
+
return (_jsx(LoaderCircle, { ...attributes, "aria-hidden": true, ...props, ref: ref, strokeWidth: strokeWidth, "data-component": "textarea-addonloadingicon", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
171
|
+
});
|
|
172
|
+
const InputContext = createContext(null);
|
|
173
|
+
function useInputContext() {
|
|
174
|
+
const context = useContext(InputContext);
|
|
175
|
+
if (!context)
|
|
176
|
+
throw new globalThis.Error('Parts must be inside Root');
|
|
177
|
+
return context;
|
|
178
|
+
}
|
|
179
|
+
function usePartAttributes() {
|
|
180
|
+
const context = useInputContext();
|
|
181
|
+
const tone = useToneContext();
|
|
182
|
+
return {
|
|
183
|
+
'data-disabled': context.disabled ? '' : undefined,
|
|
184
|
+
'data-readonly': context.readOnly ? '' : undefined,
|
|
185
|
+
'data-required': context.required ? '' : undefined,
|
|
186
|
+
'data-tone': tone,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function useMessageId(id) {
|
|
190
|
+
const generatedId = useId();
|
|
191
|
+
const messageId = id ?? generatedId;
|
|
192
|
+
const context = useInputContext();
|
|
193
|
+
useEffect(() => {
|
|
194
|
+
context.setConnections((current) => ({
|
|
195
|
+
...current,
|
|
196
|
+
descriptionIds: [...current.descriptionIds, messageId],
|
|
197
|
+
}));
|
|
198
|
+
return () => context.setConnections((current) => ({
|
|
199
|
+
...current,
|
|
200
|
+
descriptionIds: current.descriptionIds.filter((id) => id !== messageId),
|
|
201
|
+
}));
|
|
202
|
+
}, [messageId, context.setConnections]);
|
|
203
|
+
return messageId;
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/textarea/index.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,IAAI,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AY,CAAC,EAAW;IAC/B,MAAM,WAAW,GAAG,KAAK,EAAE,CAAA;IAC3B,MAAM,SAAS,GAAG,EAAE,IAAI,WAAW,CAAA;IACnC,MAAM,OAAO,GAAG,eAAe,EAAE,CAAA;IACjC,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACnC,GAAG,OAAO;YACV,cAAc,EAAE,CAAC,GAAG,OAAO,CAAC,cAAc,EAAE,SAAS,CAAC;SACvD,CAAC,CAAC,CAAA;QACH,OAAO,GAAG,EAAE,CACV,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACnC,GAAG,OAAO;YACV,cAAc,EAAE,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,SAAS,CAAC;SACxE,CAAC,CAAC,CAAA;IACP,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAA;IACvC,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { StyleProps } from '../../types/Style.ts';
|
|
2
|
+
import type { ComponentProps, HTMLAttributes, ReactElement } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Adds preset styling to one link child without rendering a wrapper or handling navigation.
|
|
5
|
+
* Pass a native anchor or your router's Link; put the destination and navigation props
|
|
6
|
+
* on that child. Custom link components must forward className, style, and data-*
|
|
7
|
+
* attributes to their anchor. Supply one element, not text, a fragment, or a list.
|
|
8
|
+
*
|
|
9
|
+
* @example Complete composition
|
|
10
|
+
* import { TextLink } from '@central-ui/react'
|
|
11
|
+
* import { Link } from '@tanstack/react-router'
|
|
12
|
+
*
|
|
13
|
+
* function Example() {
|
|
14
|
+
* return (
|
|
15
|
+
* <p className="text-sm text-neutral-600">
|
|
16
|
+
* Need help?{' '}
|
|
17
|
+
* <TextLink.default>
|
|
18
|
+
* <Link to="/demo">Read the guide</Link>
|
|
19
|
+
* </TextLink.default>.
|
|
20
|
+
* </p>
|
|
21
|
+
* )
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @example Native anchor, without a router
|
|
25
|
+
* <TextLink.default>
|
|
26
|
+
* <a href="https://example.com/help" target="_blank" rel="noreferrer">
|
|
27
|
+
* Read the guide
|
|
28
|
+
* </a>
|
|
29
|
+
* </TextLink.default>
|
|
30
|
+
*/
|
|
31
|
+
export default function TextLink({ disableStyle, children, className, style, ...props }: Omit<HTMLAttributes<HTMLAnchorElement>, 'children'> & StyleProps & {
|
|
32
|
+
/**
|
|
33
|
+
* Required link to style: a native anchor or a router Link that forwards
|
|
34
|
+
* className, style, and data-* attributes to its anchor. Keep navigation props
|
|
35
|
+
* on this child; TextLink only supplies styling and renders no extra element.
|
|
36
|
+
*/
|
|
37
|
+
children: ReactElement<ComponentProps<'a'>>;
|
|
38
|
+
}): ReactElement<import("react").DetailedHTMLProps<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, string | import("react").JSXElementConstructor<any>>;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/textlink/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAGzE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EACT,EAAE,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,EAAE,UAAU,CAAC,GACpD,UAAU,GAAG;IACX;;;;OAIG;IACH,QAAQ,EAAE,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAA;CAC5C,oLAUF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { cloneElement } from 'react';
|
|
2
|
+
import { twMerge } from 'tailwind-merge';
|
|
3
|
+
/**
|
|
4
|
+
* Adds preset styling to one link child without rendering a wrapper or handling navigation.
|
|
5
|
+
* Pass a native anchor or your router's Link; put the destination and navigation props
|
|
6
|
+
* on that child. Custom link components must forward className, style, and data-*
|
|
7
|
+
* attributes to their anchor. Supply one element, not text, a fragment, or a list.
|
|
8
|
+
*
|
|
9
|
+
* @example Complete composition
|
|
10
|
+
* import { TextLink } from '@central-ui/react'
|
|
11
|
+
* import { Link } from '@tanstack/react-router'
|
|
12
|
+
*
|
|
13
|
+
* function Example() {
|
|
14
|
+
* return (
|
|
15
|
+
* <p className="text-sm text-neutral-600">
|
|
16
|
+
* Need help?{' '}
|
|
17
|
+
* <TextLink.default>
|
|
18
|
+
* <Link to="/demo">Read the guide</Link>
|
|
19
|
+
* </TextLink.default>.
|
|
20
|
+
* </p>
|
|
21
|
+
* )
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @example Native anchor, without a router
|
|
25
|
+
* <TextLink.default>
|
|
26
|
+
* <a href="https://example.com/help" target="_blank" rel="noreferrer">
|
|
27
|
+
* Read the guide
|
|
28
|
+
* </a>
|
|
29
|
+
* </TextLink.default>
|
|
30
|
+
*/
|
|
31
|
+
export default function TextLink({ disableStyle, children, className, style, ...props }) {
|
|
32
|
+
return cloneElement(children, {
|
|
33
|
+
...props,
|
|
34
|
+
...{
|
|
35
|
+
'data-component': 'textlink-textlink',
|
|
36
|
+
'data-style-disabled': disableStyle ? '' : undefined,
|
|
37
|
+
},
|
|
38
|
+
className: twMerge(children.props.className, className),
|
|
39
|
+
style: { ...children.props.style, ...style },
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/textlink/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAEpC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EASP;IACD,OAAO,YAAY,CAAC,QAAQ,EAAE;QAC5B,GAAG,KAAK;QACR,GAAG;YACD,gBAAgB,EAAE,mBAAmB;YACrC,qBAAqB,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;SACrD;QACD,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC;QACvD,KAAK,EAAE,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE;KAC7C,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { StyleProps } from '../../types/Style.ts';
|
|
2
|
+
import { Toast as BaseToast } from '@base-ui/react/toast';
|
|
3
|
+
import type { ComponentProps, ReactElement, ReactNode } from 'react';
|
|
4
|
+
export type ProviderProps = Omit<BaseToast.Provider.Props, 'toastManager'> & Pick<BaseToast.Viewport.Props, 'style'> & {
|
|
5
|
+
className?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Mount Provider once before calling Show. Show receives the notification composition; do not render Toast directly outside it. Icon follows Root tone automatically. For urgent priority, supply title/description in Show options so the live region can announce them.
|
|
9
|
+
*
|
|
10
|
+
* @example Complete composition
|
|
11
|
+
* import { Toast } from '@central-ui/react'
|
|
12
|
+
*
|
|
13
|
+
* function Example() {
|
|
14
|
+
* return (
|
|
15
|
+
* <Toast.Provider>
|
|
16
|
+
* <button
|
|
17
|
+
* type="button"
|
|
18
|
+
* onClick={() =>
|
|
19
|
+
* Toast.Show(() => (
|
|
20
|
+
* <Toast.Root tone="success">
|
|
21
|
+
* <Toast.Toast>
|
|
22
|
+
* <Toast.Icon />
|
|
23
|
+
* <Toast.Description>Changes saved.</Toast.Description>
|
|
24
|
+
* <Toast.CloseButton>
|
|
25
|
+
* <Toast.CloseButtonIcon />
|
|
26
|
+
* </Toast.CloseButton>
|
|
27
|
+
* </Toast.Toast>
|
|
28
|
+
* </Toast.Root>
|
|
29
|
+
* ))
|
|
30
|
+
* }
|
|
31
|
+
* >
|
|
32
|
+
* Save changes
|
|
33
|
+
* </button>
|
|
34
|
+
* </Toast.Provider>
|
|
35
|
+
* )
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* @example Keep a notification until it is dismissed
|
|
39
|
+
* // Provider must already be mounted; timeout belongs to Show options.
|
|
40
|
+
* Toast.Show(
|
|
41
|
+
* () => (
|
|
42
|
+
* <Toast.Root>
|
|
43
|
+
* <Toast.Toast>
|
|
44
|
+
* <Toast.Description>Review the changes.</Toast.Description>
|
|
45
|
+
* <Toast.CloseButton>
|
|
46
|
+
* <Toast.CloseButtonIcon />
|
|
47
|
+
* </Toast.CloseButton>
|
|
48
|
+
* </Toast.Toast>
|
|
49
|
+
* </Toast.Root>
|
|
50
|
+
* ),
|
|
51
|
+
* { timeout: 0 },
|
|
52
|
+
* )
|
|
53
|
+
*/
|
|
54
|
+
export declare function Provider({ children, timeout, limit, className, style, }: ProviderProps): import("react").JSX.Element;
|
|
55
|
+
export type ShowOptions = Omit<Parameters<ReturnType<typeof BaseToast.createToastManager<NotificationData>>['add']>[0], 'data' | 'positionerProps'> & {
|
|
56
|
+
/** Attach application metadata to a notification; its render callback is reserved for the library. */
|
|
57
|
+
data?: Omit<NotificationData, 'render'>;
|
|
58
|
+
};
|
|
59
|
+
/** Provider must be mounted first. For priority='high', supply title/description options: Base UI's separate urgent live region reads these fields, not data.render. */
|
|
60
|
+
export declare function Show(render: () => ReactElement, options?: ShowOptions): string;
|
|
61
|
+
export declare function Root({ tone, children, }: {
|
|
62
|
+
/** Choose the visual tone. This does not validate data or show/hide feedback messages. */
|
|
63
|
+
tone?: 'neutral' | 'success' | 'error';
|
|
64
|
+
children: ReactNode;
|
|
65
|
+
}): import("react").JSX.Element;
|
|
66
|
+
export type ToastProps = Omit<BaseToast.Root.Props, 'toast' | 'className'> & {
|
|
67
|
+
className?: string;
|
|
68
|
+
} & StyleProps;
|
|
69
|
+
export declare const Toast: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").ToastRootProps, "className" | "toast"> & {
|
|
70
|
+
className?: string;
|
|
71
|
+
} & StyleProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
72
|
+
/** A default icon is supplied. Omit children for the usual case; pass an icon only to replace that visual. */
|
|
73
|
+
export declare function Icon({ disableStyle, children, className, ...props }: (Omit<ComponentProps<'svg'>, 'children'> & {
|
|
74
|
+
/** Omit for the supplied default icon; pass a child only to replace it. */
|
|
75
|
+
children?: ReactElement<ComponentProps<'svg'> & {
|
|
76
|
+
'data-tone'?: string;
|
|
77
|
+
}>;
|
|
78
|
+
}) & StyleProps): import("react").FunctionComponentElement<any>;
|
|
79
|
+
export declare const Title: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").ToastTitleProps, "className"> & {
|
|
80
|
+
className?: string;
|
|
81
|
+
} & StyleProps, "ref"> & import("react").RefAttributes<HTMLHeadingElement>>;
|
|
82
|
+
export declare const Description: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").ToastDescriptionProps, "className"> & {
|
|
83
|
+
className?: string;
|
|
84
|
+
} & StyleProps, "ref"> & import("react").RefAttributes<HTMLParagraphElement>>;
|
|
85
|
+
/** Behavior only: give your child control this action. Style the child itself; this wrapper has no preset appearance or disableStyle prop. */
|
|
86
|
+
export declare const CloseHandler: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").ToastCloseProps, "children" | "className" | "render"> & {
|
|
87
|
+
className?: string;
|
|
88
|
+
/** Supply your own accessible control. It receives the behavior; its own className owns the appearance. */
|
|
89
|
+
children: ReactElement;
|
|
90
|
+
}, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
91
|
+
export declare const CloseButton: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").ToastCloseProps, "className"> & {
|
|
92
|
+
className?: string;
|
|
93
|
+
} & StyleProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
94
|
+
export declare const ActionButton: import("react").ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").ToastActionProps, "className"> & {
|
|
95
|
+
className?: string;
|
|
96
|
+
} & StyleProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
97
|
+
/** A default icon is supplied. Omit children for the usual case; pass an icon only to replace that visual. */
|
|
98
|
+
export declare function CloseButtonIcon({ disableStyle, children, className, ...props }: (Omit<ComponentProps<'svg'>, 'children'> & {
|
|
99
|
+
/** Omit for the supplied default icon; pass a child only to replace it. */
|
|
100
|
+
children?: ReactElement<ComponentProps<'svg'> & {
|
|
101
|
+
'data-tone'?: string;
|
|
102
|
+
}>;
|
|
103
|
+
}) & StyleProps): ReactElement<import("react").SVGProps<SVGSVGElement> & {
|
|
104
|
+
'data-tone'?: string;
|
|
105
|
+
}, string | import("react").JSXElementConstructor<any>>;
|
|
106
|
+
type NotificationData = {
|
|
107
|
+
render: () => ReactElement;
|
|
108
|
+
[key: string]: unknown;
|
|
109
|
+
};
|
|
110
|
+
export {};
|
|
111
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/toast/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAA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@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Toast as BaseToast } from '@base-ui/react/toast';
|
|
3
|
+
import { CircleCheck, Info, TriangleAlert, X } from 'lucide-react';
|
|
4
|
+
import { cloneElement, createContext, forwardRef, useContext, useEffect, useState, } from 'react';
|
|
5
|
+
import { twMerge } from 'tailwind-merge';
|
|
6
|
+
/**
|
|
7
|
+
* Mount Provider once before calling Show. Show receives the notification composition; do not render Toast directly outside it. Icon follows Root tone automatically. For urgent priority, supply title/description in Show options so the live region can announce them.
|
|
8
|
+
*
|
|
9
|
+
* @example Complete composition
|
|
10
|
+
* import { Toast } from '@central-ui/react'
|
|
11
|
+
*
|
|
12
|
+
* function Example() {
|
|
13
|
+
* return (
|
|
14
|
+
* <Toast.Provider>
|
|
15
|
+
* <button
|
|
16
|
+
* type="button"
|
|
17
|
+
* onClick={() =>
|
|
18
|
+
* Toast.Show(() => (
|
|
19
|
+
* <Toast.Root tone="success">
|
|
20
|
+
* <Toast.Toast>
|
|
21
|
+
* <Toast.Icon />
|
|
22
|
+
* <Toast.Description>Changes saved.</Toast.Description>
|
|
23
|
+
* <Toast.CloseButton>
|
|
24
|
+
* <Toast.CloseButtonIcon />
|
|
25
|
+
* </Toast.CloseButton>
|
|
26
|
+
* </Toast.Toast>
|
|
27
|
+
* </Toast.Root>
|
|
28
|
+
* ))
|
|
29
|
+
* }
|
|
30
|
+
* >
|
|
31
|
+
* Save changes
|
|
32
|
+
* </button>
|
|
33
|
+
* </Toast.Provider>
|
|
34
|
+
* )
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* @example Keep a notification until it is dismissed
|
|
38
|
+
* // Provider must already be mounted; timeout belongs to Show options.
|
|
39
|
+
* Toast.Show(
|
|
40
|
+
* () => (
|
|
41
|
+
* <Toast.Root>
|
|
42
|
+
* <Toast.Toast>
|
|
43
|
+
* <Toast.Description>Review the changes.</Toast.Description>
|
|
44
|
+
* <Toast.CloseButton>
|
|
45
|
+
* <Toast.CloseButtonIcon />
|
|
46
|
+
* </Toast.CloseButton>
|
|
47
|
+
* </Toast.Toast>
|
|
48
|
+
* </Toast.Root>
|
|
49
|
+
* ),
|
|
50
|
+
* { timeout: 0 },
|
|
51
|
+
* )
|
|
52
|
+
*/
|
|
53
|
+
export function Provider({ children, timeout = 4000, limit = 3, className, style, }) {
|
|
54
|
+
const [manager] = useState(() => BaseToast.createToastManager());
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
activeManager = manager;
|
|
57
|
+
return () => {
|
|
58
|
+
if (activeManager === manager)
|
|
59
|
+
activeManager = undefined;
|
|
60
|
+
};
|
|
61
|
+
}, [manager]);
|
|
62
|
+
return (_jsxs(BaseToast.Provider, { toastManager: manager, timeout: timeout, limit: limit, children: [children, _jsx(Notifications, { className: className, style: style })] }));
|
|
63
|
+
}
|
|
64
|
+
/** Provider must be mounted first. For priority='high', supply title/description options: Base UI's separate urgent live region reads these fields, not data.render. */
|
|
65
|
+
export function Show(render, options) {
|
|
66
|
+
// Base UI has no Show(JSX) API. Its native data field carries our render callback;
|
|
67
|
+
// Notifications invokes it during React rendering and supplies the notification via context.
|
|
68
|
+
// This is our composition convention; the native manager still owns the toast lifecycle.
|
|
69
|
+
if (!activeManager)
|
|
70
|
+
throw new Error('Mount Toast.Provider before calling Toast.Show');
|
|
71
|
+
return activeManager.add({ ...options, data: { ...options?.data, render } });
|
|
72
|
+
}
|
|
73
|
+
export function Root({ tone = 'neutral', children, }) {
|
|
74
|
+
return _jsx(ToneContext.Provider, { value: tone, children: children });
|
|
75
|
+
}
|
|
76
|
+
export const Toast = forwardRef(function Toast({ disableStyle, className, style, children, ...props }, ref) {
|
|
77
|
+
const notification = useNotificationContext();
|
|
78
|
+
const tone = useContext(ToneContext);
|
|
79
|
+
return (_jsx(BaseToast.Root, { ...props, ref: ref, toast: notification, "data-tone": tone, "data-component": "toast-toast", "data-style-disabled": disableStyle ? '' : undefined, className: className, style: (state) => {
|
|
80
|
+
// Base UI measures heights and provides offsets; the legacy stack adds a 16px gap.
|
|
81
|
+
const offsetY = state.expanded
|
|
82
|
+
? 'calc(-1 * (var(--toast-offset-y, 0px) + var(--toast-index) * 16px))'
|
|
83
|
+
: 'calc(var(--toast-index) * -16px)';
|
|
84
|
+
const starting = state.transitionStatus === 'starting';
|
|
85
|
+
const ending = state.transitionStatus === 'ending';
|
|
86
|
+
const horizontalExit = ending &&
|
|
87
|
+
(state.swipeDirection === 'left' ||
|
|
88
|
+
state.swipeDirection === 'right');
|
|
89
|
+
const x = horizontalExit
|
|
90
|
+
? 'calc(var(--toast-swipe-movement-x, 0px) + ' +
|
|
91
|
+
(state.swipeDirection === 'left' ? '-150%' : '150%') +
|
|
92
|
+
')'
|
|
93
|
+
: 'var(--toast-swipe-movement-x, 0px)';
|
|
94
|
+
const y = starting
|
|
95
|
+
? '150%'
|
|
96
|
+
: ending && !horizontalExit
|
|
97
|
+
? 'calc(var(--toast-swipe-movement-y, 0px) + ' +
|
|
98
|
+
(state.swipeDirection === 'up' ? '-150%' : '150%') +
|
|
99
|
+
')'
|
|
100
|
+
: 'calc(' + offsetY + ' + var(--toast-swipe-movement-y, 0px))';
|
|
101
|
+
return {
|
|
102
|
+
transform: 'translateX(' +
|
|
103
|
+
x +
|
|
104
|
+
') translateY(' +
|
|
105
|
+
y +
|
|
106
|
+
') scale(' +
|
|
107
|
+
(state.expanded
|
|
108
|
+
? '1'
|
|
109
|
+
: 'max(0, calc(1 - var(--toast-index) * 0.05))') +
|
|
110
|
+
')',
|
|
111
|
+
transformOrigin: 'bottom center',
|
|
112
|
+
zIndex: 'calc(1000 - var(--toast-index))',
|
|
113
|
+
height: state.expanded
|
|
114
|
+
? 'var(--toast-height)'
|
|
115
|
+
: 'var(--toast-frontmost-height, var(--toast-height))',
|
|
116
|
+
opacity: starting || ending || state.limited ? 0 : 1,
|
|
117
|
+
pointerEvents: state.limited ? 'none' : 'auto',
|
|
118
|
+
willChange: 'transform, opacity, height',
|
|
119
|
+
transition: state.swiping
|
|
120
|
+
? 'none'
|
|
121
|
+
: 'transform 400ms, opacity 400ms, height 400ms, box-shadow 200ms',
|
|
122
|
+
transitionTimingFunction: 'cubic-bezier(0.21, 1.02, 0.73, 1)',
|
|
123
|
+
...(typeof style === 'function' ? style(state) : style),
|
|
124
|
+
};
|
|
125
|
+
}, children: _jsx(BaseToast.Content, { "data-component": "toast-toast-1", children: children }) }));
|
|
126
|
+
});
|
|
127
|
+
/** A default icon is supplied. Omit children for the usual case; pass an icon only to replace that visual. */
|
|
128
|
+
export function Icon({ disableStyle, children, className, ...props }) {
|
|
129
|
+
const tone = useContext(ToneContext);
|
|
130
|
+
const icon = children ??
|
|
131
|
+
(tone === 'success' ? (_jsx(CircleCheck, {})) : tone === 'error' ? (_jsx(TriangleAlert, {})) : (_jsx(Info, {})));
|
|
132
|
+
return cloneElement(icon, {
|
|
133
|
+
...icon.props,
|
|
134
|
+
...props,
|
|
135
|
+
'aria-hidden': true,
|
|
136
|
+
'data-tone': tone,
|
|
137
|
+
...{
|
|
138
|
+
'data-component': 'toast-icon',
|
|
139
|
+
'data-style-disabled': disableStyle ? '' : undefined,
|
|
140
|
+
},
|
|
141
|
+
className: twMerge(icon.props.className, className),
|
|
142
|
+
strokeWidth: props.strokeWidth ?? icon.props.strokeWidth ?? 1.8,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
export const Title = forwardRef(function Title({ disableStyle, className, ...props }, ref) {
|
|
146
|
+
return (_jsx(BaseToast.Title, { ...props, ref: ref, "data-component": "toast-title", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
147
|
+
});
|
|
148
|
+
export const Description = forwardRef(function Description({ disableStyle, className, ...props }, ref) {
|
|
149
|
+
return (_jsx(BaseToast.Description, { ...props, ref: ref, "data-component": "toast-description", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
150
|
+
});
|
|
151
|
+
/** Behavior only: give your child control this action. Style the child itself; this wrapper has no preset appearance or disableStyle prop. */
|
|
152
|
+
export const CloseHandler = forwardRef(function CloseHandler({ children, ...props }, ref) {
|
|
153
|
+
return (_jsx(BaseToast.Close, { ...props, ref: ref, render: children, className: props.className }));
|
|
154
|
+
});
|
|
155
|
+
export const CloseButton = forwardRef(function CloseButton({ disableStyle, className, ...props }, ref) {
|
|
156
|
+
return (_jsx(BaseToast.Close, { "aria-label": "Dismiss notification", ...props, ref: ref, "data-component": "toast-closebutton", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
157
|
+
});
|
|
158
|
+
export const ActionButton = forwardRef(function ActionButton({ disableStyle, className, ...props }, ref) {
|
|
159
|
+
return (_jsx(BaseToast.Action, { ...props, ref: ref, "data-component": "toast-actionbutton", "data-style-disabled": disableStyle ? '' : undefined, className: className }));
|
|
160
|
+
});
|
|
161
|
+
/** A default icon is supplied. Omit children for the usual case; pass an icon only to replace that visual. */
|
|
162
|
+
export function CloseButtonIcon({ disableStyle, children = _jsx(X, {}), className, ...props }) {
|
|
163
|
+
const tone = useContext(ToneContext);
|
|
164
|
+
return cloneElement(children, {
|
|
165
|
+
...children.props,
|
|
166
|
+
...props,
|
|
167
|
+
'aria-hidden': true,
|
|
168
|
+
'data-tone': tone,
|
|
169
|
+
...{
|
|
170
|
+
'data-component': 'toast-closebuttonicon',
|
|
171
|
+
'data-style-disabled': disableStyle ? '' : undefined,
|
|
172
|
+
},
|
|
173
|
+
className: twMerge(children.props.className, className),
|
|
174
|
+
strokeWidth: props.strokeWidth ?? children.props.strokeWidth ?? 2,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
// Private: every callback-rendered composition receives the native object required by Toast.Root.
|
|
178
|
+
function Notifications({ className, style, }) {
|
|
179
|
+
const { toasts } = BaseToast.useToastManager();
|
|
180
|
+
const visible = toasts.filter((notification) => !notification.limited && notification.transitionStatus !== 'ending');
|
|
181
|
+
return (_jsx(BaseToast.Portal, { children: _jsx(BaseToast.Viewport, { className: className, style: (state) => ({
|
|
182
|
+
position: 'fixed',
|
|
183
|
+
bottom: 24,
|
|
184
|
+
left: '50%',
|
|
185
|
+
transform: 'translateX(-50%)',
|
|
186
|
+
width: 'min(400px, calc(100vw - 48px))',
|
|
187
|
+
zIndex: 1000,
|
|
188
|
+
height: state.expanded
|
|
189
|
+
? visible.reduce((total, notification) => total + (notification.height ?? 0), 0) +
|
|
190
|
+
Math.max(0, visible.length - 1) * 16
|
|
191
|
+
: (visible[0]?.height ?? 0) + Math.max(0, visible.length - 1) * 16,
|
|
192
|
+
pointerEvents: visible.length ? 'auto' : 'none',
|
|
193
|
+
...(typeof style === 'function' ? style(state) : style),
|
|
194
|
+
}), children: toasts.map((notification) => (_jsx(NotificationContext.Provider, { value: notification, children: notification.data.render() }, notification.id))) }) }));
|
|
195
|
+
}
|
|
196
|
+
let activeManager;
|
|
197
|
+
const NotificationContext = createContext(null);
|
|
198
|
+
const ToneContext = createContext('neutral');
|
|
199
|
+
function useNotificationContext() {
|
|
200
|
+
const notification = useContext(NotificationContext);
|
|
201
|
+
if (!notification)
|
|
202
|
+
throw new Error('Toast.Toast must be rendered by Toast.Show');
|
|
203
|
+
return notification;
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=index.js.map
|