@economic/taco 0.0.26-alpha.9 → 0.0.28-alpha.5
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/dist/components/Combobox/useCombobox.d.ts +1 -1
- package/dist/components/Datepicker/Datepicker.d.ts +1 -1
- package/dist/components/Field/Field.d.ts +19 -11
- package/dist/components/Menu/Menu.d.ts +3 -0
- package/dist/components/SearchInput/SearchInput.d.ts +1 -1
- package/dist/esm/components/Button/Button.js +3 -4
- package/dist/esm/components/Button/Button.js.map +1 -1
- package/dist/esm/components/Button/util.js +3 -2
- package/dist/esm/components/Button/util.js.map +1 -1
- package/dist/esm/components/Checkbox/Checkbox.js +5 -5
- package/dist/esm/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/components/Combobox/Combobox.js +10 -5
- package/dist/esm/components/Combobox/Combobox.js.map +1 -1
- package/dist/esm/components/Combobox/useCombobox.js +1 -1
- package/dist/esm/components/Combobox/useCombobox.js.map +1 -1
- package/dist/esm/components/Field/Field.js +16 -38
- package/dist/esm/components/Field/Field.js.map +1 -1
- package/dist/esm/components/Hanger/Hanger.js +14 -3
- package/dist/esm/components/Hanger/Hanger.js.map +1 -1
- package/dist/esm/components/IconButton/IconButton.js +3 -4
- package/dist/esm/components/IconButton/IconButton.js.map +1 -1
- package/dist/esm/components/Input/Input.js +2 -3
- package/dist/esm/components/Input/Input.js.map +1 -1
- package/dist/esm/components/Input/util.js +1 -1
- package/dist/esm/components/Input/util.js.map +1 -1
- package/dist/esm/components/Listbox/Listbox.js.map +1 -1
- package/dist/esm/components/Listbox/ScrollableList.js +11 -0
- package/dist/esm/components/Listbox/ScrollableList.js.map +1 -1
- package/dist/esm/components/Menu/Menu.js +4 -3
- package/dist/esm/components/Menu/Menu.js.map +1 -1
- package/dist/esm/components/RadioGroup/RadioGroup.js +2 -2
- package/dist/esm/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/esm/components/SearchInput/SearchInput.js +1 -1
- package/dist/esm/components/SearchInput/SearchInput.js.map +1 -1
- package/dist/esm/components/Select/Select.js +1 -1
- package/dist/esm/components/Select/Select.js.map +1 -1
- package/dist/esm/components/Select/useSelect.js +10 -4
- package/dist/esm/components/Select/useSelect.js.map +1 -1
- package/dist/esm/components/Switch/Switch.js +2 -2
- package/dist/esm/components/Switch/Switch.js.map +1 -1
- package/dist/esm/components/Table/util/renderColumn.js +1 -1
- package/dist/esm/components/Table/util/renderColumn.js.map +1 -1
- package/dist/esm/components/Textarea/Textarea.js.map +1 -1
- package/dist/esm/index.css +2 -1
- package/dist/index.css +2 -1
- package/dist/taco.cjs.development.js +88 -77
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/dist/utils/tailwind.d.ts +1 -0
- package/package.json +17 -17
- package/types.json +418 -440
@@ -15,5 +15,5 @@ declare type useCombobox = React.HTMLAttributes<HTMLDivElement> & {
|
|
15
15
|
onOpenChange: (open: boolean) => void;
|
16
16
|
};
|
17
17
|
};
|
18
|
-
export declare const useCombobox: ({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, data: unfilteredData, defaultValue, disabled, inline, loading: __, onChange, onClick, onKeyDown, onSearch, readOnly, value, ...props }: Omit<ComboboxProps, 'dialog'>, ref: React.Ref<HTMLInputElement>) => useCombobox;
|
18
|
+
export declare const useCombobox: ({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, data: unfilteredData, defaultValue, disabled, id: nativeId, inline, loading: __, onChange, onClick, onKeyDown, onSearch, readOnly, value, ...props }: Omit<ComboboxProps, 'dialog'>, ref: React.Ref<HTMLInputElement>) => useCombobox;
|
19
19
|
export {};
|
@@ -29,7 +29,7 @@ export declare type DatepickerProps = Omit<InputProps, 'value'> & {
|
|
29
29
|
*/
|
30
30
|
value?: Date;
|
31
31
|
};
|
32
|
-
export declare const Datepicker: React.ForwardRefExoticComponent<Pick<InputProps, "accept" | "alt" | "autoComplete" | "autoFocus" | "capture" | "checked" | "crossOrigin" | "disabled" | "enterKeyHint" | "form" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "height" | "list" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "name" | "pattern" | "placeholder" | "readOnly" | "required" | "size" | "src" | "step" | "type" | "width" | "onChange" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "button" | "icon" | "highlighted" | "
|
32
|
+
export declare const Datepicker: React.ForwardRefExoticComponent<Pick<InputProps, "accept" | "alt" | "autoComplete" | "autoFocus" | "capture" | "checked" | "crossOrigin" | "disabled" | "enterKeyHint" | "form" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "height" | "list" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "name" | "pattern" | "placeholder" | "readOnly" | "required" | "size" | "src" | "step" | "type" | "width" | "onChange" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "button" | "icon" | "highlighted" | "state"> & {
|
33
33
|
/** [Calendar](component:calendar) component associated with the DatePicker */
|
34
34
|
calendar?: CalendarProps | undefined;
|
35
35
|
/** List of shortcuts */
|
@@ -1,18 +1,26 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import './Field.css';
|
3
|
-
export declare type FieldProps =
|
4
|
-
|
3
|
+
export declare type FieldProps = React.LabelHTMLAttributes<HTMLLabelElement> & {
|
4
|
+
/** Content of the field */
|
5
|
+
children: React.ReactNode;
|
6
|
+
/** Changes the style to indicate the element is disabled */
|
5
7
|
disabled?: boolean;
|
6
8
|
invalid?: boolean;
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
/**
|
10
|
+
* Text displayed below the children of Field.
|
11
|
+
* Should be a short text that indicates feedback for user.
|
12
|
+
*/
|
13
|
+
message?: string;
|
10
14
|
};
|
11
|
-
export declare const Field: React.ForwardRefExoticComponent<
|
12
|
-
|
15
|
+
export declare const Field: React.ForwardRefExoticComponent<React.LabelHTMLAttributes<HTMLLabelElement> & {
|
16
|
+
/** Content of the field */
|
17
|
+
children: React.ReactNode;
|
18
|
+
/** Changes the style to indicate the element is disabled */
|
13
19
|
disabled?: boolean | undefined;
|
14
20
|
invalid?: boolean | undefined;
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
21
|
+
/**
|
22
|
+
* Text displayed below the children of Field.
|
23
|
+
* Should be a short text that indicates feedback for user.
|
24
|
+
*/
|
25
|
+
message?: string | undefined;
|
26
|
+
} & React.RefAttributes<HTMLLabelElement>>;
|
@@ -1,6 +1,9 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
|
3
|
+
import { Appearance } from '../..';
|
3
4
|
export declare type MenuProps = {
|
5
|
+
/** Appearance will change the style of the button */
|
6
|
+
appearance?: Appearance;
|
4
7
|
children: React.ReactNode;
|
5
8
|
id?: string;
|
6
9
|
/** A trigger to be used for the menu, should not be set if `children` already contains a trigger */
|
@@ -10,7 +10,7 @@ export declare type SearchInputProps = Omit<InputProps, 'icon'> & {
|
|
10
10
|
/** Current input value will be passed to the method. In order to get the value, the component must be controlled otherwise value will always be undefined */
|
11
11
|
onSearch?: (value: string | number | readonly string[] | undefined) => void;
|
12
12
|
};
|
13
|
-
export declare const SearchInput: React.ForwardRefExoticComponent<Pick<InputProps, "accept" | "alt" | "autoComplete" | "autoFocus" | "capture" | "checked" | "crossOrigin" | "disabled" | "enterKeyHint" | "form" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "height" | "list" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "name" | "pattern" | "placeholder" | "readOnly" | "required" | "size" | "src" | "step" | "type" | "value" | "width" | "onChange" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "button" | "highlighted" | "
|
13
|
+
export declare const SearchInput: React.ForwardRefExoticComponent<Pick<InputProps, "accept" | "alt" | "autoComplete" | "autoFocus" | "capture" | "checked" | "crossOrigin" | "disabled" | "enterKeyHint" | "form" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "height" | "list" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "name" | "pattern" | "placeholder" | "readOnly" | "required" | "size" | "src" | "step" | "type" | "value" | "width" | "onChange" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "button" | "highlighted" | "state"> & {
|
14
14
|
/** Current input value will be passed to the method. In order to get the value, the component must be controlled otherwise value will always be undefined */
|
15
15
|
onSearch?: ((value: string | number | readonly string[] | undefined) => void) | undefined;
|
16
16
|
} & React.RefAttributes<HTMLInputElement>>;
|
@@ -4,13 +4,12 @@ import cn from 'classnames';
|
|
4
4
|
import { Icon } from '../Icon/Icon.js';
|
5
5
|
import { getButtonClasses, getAppearanceClasses, createButton } from './util.js';
|
6
6
|
|
7
|
-
var _excluded = ["
|
7
|
+
var _excluded = ["fluid"];
|
8
8
|
var Button = /*#__PURE__*/forwardRef(function Button(props, ref) {
|
9
|
-
var
|
10
|
-
fluid = props.fluid,
|
9
|
+
var fluid = props.fluid,
|
11
10
|
otherProps = _objectWithoutPropertiesLoose(props, _excluded);
|
12
11
|
|
13
|
-
var className = cn(getButtonClasses(), getAppearanceClasses(appearance), 'rounded px-3', {
|
12
|
+
var className = cn(getButtonClasses(), getAppearanceClasses(otherProps.appearance), 'rounded px-3', {
|
14
13
|
'cursor-not-allowed opacity-50': props.disabled,
|
15
14
|
'focus:yt-focus active:focus:yt-focus': !props.disabled,
|
16
15
|
'w-full': fluid
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Button.js","sources":["../../../../src/components/Button/Button.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport { Appearance } from '../../types';\nimport * as ButtonPrimitive from '../../primitives/Button';\nimport { getAppearanceClasses, getButtonClasses, createButton } from './util';\nimport { HangerProps } from '../Hanger/Hanger';\nimport { MenuProps } from '../Menu/Menu';\nimport { DialogProps } from '../Dialog/Dialog';\nimport { PopoverProps } from '../Popover/Popover';\nimport './Button.css';\nimport { Icon } from '../Icon/Icon';\n\nexport type ButtonProps = ButtonPrimitive.ButtonProps & {\n /** Appearance will change the style of the button */\n appearance?: Appearance;\n /**\n * Dialog component associated with the button, clicking the button will open the dialog.\n * *Note* that `onClick` event on button won't be handled, as in this case, the purpose of\n * the button should be only to open the associated dialog when clicked.\n */\n dialog?: (props: Partial<DialogProps>) => JSX.Element;\n /** If fluid, button expands to the width of it's container */\n fluid?: boolean;\n /** Hanger component associated with the button. */\n hanger?: (props: Partial<HangerProps>) => JSX.Element;\n /** Menu component associated with the button. */\n menu?: (props: Partial<MenuProps>) => JSX.Element;\n /**\n * Popover component associated with the button, clicking the button will open the popover.\n * *Note* that `onClick` event on button won't be handled, as in this case, the purpose of\n * the button should be only to open the associated popover when clicked.\n */\n popover?: (props: Partial<PopoverProps>) => JSX.Element;\n /** A tooltip to show when hovering over the button */\n tooltip?: string;\n};\n\nexport const Button = React.forwardRef(function Button(\n props: ButtonProps,\n ref: React.Ref<HTMLButtonElement | HTMLAnchorElement>\n) {\n const {
|
1
|
+
{"version":3,"file":"Button.js","sources":["../../../../src/components/Button/Button.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport { Appearance } from '../../types';\nimport * as ButtonPrimitive from '../../primitives/Button';\nimport { getAppearanceClasses, getButtonClasses, createButton } from './util';\nimport { HangerProps } from '../Hanger/Hanger';\nimport { MenuProps } from '../Menu/Menu';\nimport { DialogProps } from '../Dialog/Dialog';\nimport { PopoverProps } from '../Popover/Popover';\nimport './Button.css';\nimport { Icon } from '../Icon/Icon';\n\nexport type ButtonProps = ButtonPrimitive.ButtonProps & {\n /** Appearance will change the style of the button */\n appearance?: Appearance;\n /**\n * Dialog component associated with the button, clicking the button will open the dialog.\n * *Note* that `onClick` event on button won't be handled, as in this case, the purpose of\n * the button should be only to open the associated dialog when clicked.\n */\n dialog?: (props: Partial<DialogProps>) => JSX.Element;\n /** If fluid, button expands to the width of it's container */\n fluid?: boolean;\n /** Hanger component associated with the button. */\n hanger?: (props: Partial<HangerProps>) => JSX.Element;\n /** Menu component associated with the button. */\n menu?: (props: Partial<MenuProps>) => JSX.Element;\n /**\n * Popover component associated with the button, clicking the button will open the popover.\n * *Note* that `onClick` event on button won't be handled, as in this case, the purpose of\n * the button should be only to open the associated popover when clicked.\n */\n popover?: (props: Partial<PopoverProps>) => JSX.Element;\n /** A tooltip to show when hovering over the button */\n tooltip?: string;\n};\n\nexport const Button = React.forwardRef(function Button(\n props: ButtonProps,\n ref: React.Ref<HTMLButtonElement | HTMLAnchorElement>\n) {\n const { fluid, ...otherProps } = props;\n const className = cn(\n getButtonClasses(),\n getAppearanceClasses(otherProps.appearance),\n 'rounded px-3',\n {\n 'cursor-not-allowed opacity-50': props.disabled,\n 'focus:yt-focus active:focus:yt-focus': !props.disabled,\n 'w-full': fluid,\n },\n props.className\n );\n\n let children = otherProps.children;\n\n // add a chevron icon to menu buttons\n if (typeof otherProps.menu === 'function') {\n children = Array.isArray(children)\n ? [...children, <Icon key=\"chevron-down\" name=\"chevron-down\" />]\n : [children, <Icon key=\"chevron-down\" name=\"chevron-down\" />];\n }\n\n return createButton({ ...otherProps, children, 'data-taco': 'button' }, className, ref);\n});\n"],"names":["Button","React","props","ref","fluid","otherProps","className","cn","getButtonClasses","getAppearanceClasses","appearance","disabled","children","menu","Array","isArray","Icon","key","name","createButton"],"mappings":";;;;;;;IAqCaA,MAAM,gBAAGC,UAAA,CAAiB,SAASD,MAAT,CACnCE,KADmC,EAEnCC,GAFmC;AAInC,MAAQC,KAAR,GAAiCF,KAAjC,CAAQE,KAAR;AAAA,MAAkBC,UAAlB,iCAAiCH,KAAjC;;AACA,MAAMI,SAAS,GAAGC,EAAE,CAChBC,gBAAgB,EADA,EAEhBC,oBAAoB,CAACJ,UAAU,CAACK,UAAZ,CAFJ,EAGhB,cAHgB,EAIhB;AACI,qCAAiCR,KAAK,CAACS,QAD3C;AAEI,4CAAwC,CAACT,KAAK,CAACS,QAFnD;AAGI,cAAUP;AAHd,GAJgB,EAShBF,KAAK,CAACI,SATU,CAApB;AAYA,MAAIM,QAAQ,GAAGP,UAAU,CAACO,QAA1B;;AAGA,MAAI,OAAOP,UAAU,CAACQ,IAAlB,KAA2B,UAA/B,EAA2C;AACvCD,IAAAA,QAAQ,GAAGE,KAAK,CAACC,OAAN,CAAcH,QAAd,cACDA,QADC,GACSX,aAAA,CAACe,IAAD;AAAMC,MAAAA,GAAG,EAAC;AAAeC,MAAAA,IAAI,EAAC;KAA9B,CADT,KAEL,CAACN,QAAD,EAAWX,aAAA,CAACe,IAAD;AAAMC,MAAAA,GAAG,EAAC;AAAeC,MAAAA,IAAI,EAAC;KAA9B,CAAX,CAFN;AAGH;;AAED,SAAOC,YAAY,cAAMd,UAAN;AAAkBO,IAAAA,QAAQ,EAARA,QAAlB;AAA4B,iBAAa;AAAzC,MAAqDN,SAArD,EAAgEH,GAAhE,CAAnB;AACH,CA3BqB;;;;"}
|
@@ -5,7 +5,7 @@ import { Tooltip } from '../Tooltip/Tooltip.js';
|
|
5
5
|
|
6
6
|
var _excluded = ["dialog", "hanger", "menu", "popover", "tooltip"];
|
7
7
|
var getButtonClasses = function getButtonClasses() {
|
8
|
-
return 'min-h-[theme(spacing.8)] min-w-[theme(spacing.8)] h-max leading-6 inline-flex items-center justify-center
|
8
|
+
return 'min-h-[theme(spacing.8)] min-w-[theme(spacing.8)] h-max leading-6 inline-flex items-center justify-center border';
|
9
9
|
};
|
10
10
|
var getAppearanceClasses = function getAppearanceClasses(value, icon) {
|
11
11
|
if (icon === void 0) {
|
@@ -54,7 +54,8 @@ var createButton = function createButton(props, className, ref) {
|
|
54
54
|
});
|
55
55
|
} else if (typeof menu === 'function') {
|
56
56
|
button = menu({
|
57
|
-
trigger: button
|
57
|
+
trigger: button,
|
58
|
+
appearance: otherProps.appearance
|
58
59
|
});
|
59
60
|
} else if (typeof popover === 'function') {
|
60
61
|
button = popover({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"util.js","sources":["../../../../src/components/Button/util.tsx"],"sourcesContent":["import React from 'react';\nimport { Appearance } from '../../types';\nimport * as ButtonPrimitive from '../../primitives/Button';\nimport { Tooltip } from '../Tooltip/Tooltip';\n\nexport const getButtonClasses = () => {\n return 'min-h-[theme(spacing.8)] min-w-[theme(spacing.8)] h-max leading-6 inline-flex items-center justify-center
|
1
|
+
{"version":3,"file":"util.js","sources":["../../../../src/components/Button/util.tsx"],"sourcesContent":["import React from 'react';\nimport { Appearance } from '../../types';\nimport * as ButtonPrimitive from '../../primitives/Button';\nimport { Tooltip } from '../Tooltip/Tooltip';\n\nexport const getButtonClasses = () => {\n return 'min-h-[theme(spacing.8)] min-w-[theme(spacing.8)] h-max leading-6 inline-flex items-center justify-center border';\n};\n\nexport const getAppearanceClasses = (value: Appearance | undefined, icon = false): string => {\n switch (value) {\n case 'primary':\n return `yt-blue-solid border-blue focus:bg-blue focus:text-white focus:yt-focus active:bg-blue-dark active:text-white hover:bg-blue-light hover:border-blue-light hover:text-white hover:focus:bg-blue-light hover:focus:border-blue-light hover:focus:text-white disabled:hover:yt-blue-solid`;\n\n case 'danger':\n return `yt-red-solid border-red focus:bg-red focus:text-white focus:yt-focus-red active:bg-red-dark active:text-white hover:bg-red-light hover:text-white hover:focus:bg-red-light hover:focus:text-white disabled:hover:yt-red-solid`;\n\n case 'ghost':\n return `yt-blue-inverted focus:bg-transparent focus:text-blue focus:yt-focus active:bg-blue-lightest active:border-blue active:text-blue-dark hover:bg-blue-lightest hover:border-blue-light hover:text-blue-light hover:focus:bg-blue-lightest hover:focus:border-blue-light hover:focus:text-blue-light disabled:hover:yt-blue-inverted`;\n\n case 'discrete': {\n if (icon) {\n return `bg-transparent text-black border-transparent focus:text-black focus:yt-focus active:text-black hover:text-grey-darkest hover:focus:text-grey-darkest disabled:hover:yt-transparent`;\n }\n\n return `yt-transparent border-transparent focus:text-blue focus:yt-focus active:text-blue-dark hover:text-blue-light hover:focus:text-blue-light disabled:hover:yt-transparent`;\n }\n\n default:\n return `yt-grey-solid border-grey focus:bg-grey focus:yt-focus active:bg-grey-dark active:text-black hover:bg-grey-light hover:text-grey-darkest hover:focus:bg-grey-light hover:focus:text-grey-darkest disabled:hover:yt-grey-solid`;\n }\n};\n\nexport const createButton = (\n props: any,\n className: string,\n ref: React.Ref<HTMLButtonElement | HTMLAnchorElement>\n): JSX.Element => {\n const { dialog, hanger, menu, popover, tooltip, ...otherProps } = props;\n\n let button = <ButtonPrimitive.Button {...otherProps} className={className} ref={ref} />;\n\n if (typeof dialog === 'function') {\n button = dialog({ trigger: button });\n } else if (typeof menu === 'function') {\n button = menu({ trigger: button, appearance: otherProps.appearance });\n } else if (typeof popover === 'function') {\n button = popover({ trigger: button });\n }\n\n if (typeof hanger === 'function') {\n button = hanger({ anchor: button });\n }\n\n if (tooltip) {\n button = <Tooltip title={tooltip}>{button}</Tooltip>;\n }\n\n return button;\n};\n"],"names":["getButtonClasses","getAppearanceClasses","value","icon","createButton","props","className","ref","dialog","hanger","menu","popover","tooltip","otherProps","button","React","ButtonPrimitive","trigger","appearance","anchor","Tooltip","title"],"mappings":";;;;;;IAKaA,gBAAgB,GAAG,SAAnBA,gBAAmB;AAC5B,SAAO,kHAAP;AACH;IAEYC,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,KAAD,EAAgCC,IAAhC;MAAgCA;AAAAA,IAAAA,OAAO;;;AACvE,UAAQD,KAAR;AACI,SAAK,SAAL;AACI;;AAEJ,SAAK,QAAL;AACI;;AAEJ,SAAK,OAAL;AACI;;AAEJ,SAAK,UAAL;AAAiB;AACb,YAAIC,IAAJ,EAAU;AACN;AACH;;AAED;AACH;;AAED;AACI;AAnBR;AAqBH;IAEYC,YAAY,GAAG,SAAfA,YAAe,CACxBC,KADwB,EAExBC,SAFwB,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13 @@ var Checkbox = /*#__PURE__*/forwardRef(function Checkbox(props, ref) {
|
|
14
14
|
onChange = props.onChange,
|
15
15
|
otherProps = _objectWithoutPropertiesLoose(props, _excluded);
|
16
16
|
|
17
|
-
var className = cn('h-5 w-5 border rounded text-sm', {
|
17
|
+
var className = cn('bg-white h-5 w-5 border rounded text-sm flex-shrink-0 self-start mt-[0.1rem]', {
|
18
18
|
'mr-2': !!label,
|
19
19
|
'border-grey-dark text-blue focus:border-blue focus:yt-focus': !props.disabled && !invalid,
|
20
20
|
'border-grey text-blue-light cursor-not-allowed': props.disabled,
|
21
21
|
'bg-[rgba(255,255,0,0.2)] disabled:bg-[rgba(255,255,0,0.075)]': highlighted,
|
22
22
|
'border-red text-red focus:border-red focus:yt-focus-red': invalid && !props.disabled
|
23
|
-
}
|
23
|
+
});
|
24
24
|
var handleChange;
|
25
25
|
|
26
26
|
if (onChange) {
|
@@ -30,9 +30,9 @@ var Checkbox = /*#__PURE__*/forwardRef(function Checkbox(props, ref) {
|
|
30
30
|
}
|
31
31
|
|
32
32
|
var element = createElement(Root, Object.assign({}, otherProps, {
|
33
|
+
"data-taco": "checkbox",
|
33
34
|
checked: indeterminate ? 'indeterminate' : checked,
|
34
35
|
className: className,
|
35
|
-
"data-taco": "checkbox",
|
36
36
|
onCheckedChange: handleChange,
|
37
37
|
ref: ref
|
38
38
|
}), createElement(Indicator, {
|
@@ -45,8 +45,8 @@ var Checkbox = /*#__PURE__*/forwardRef(function Checkbox(props, ref) {
|
|
45
45
|
if (label) {
|
46
46
|
var labelClassName = cn('flex items-center cursor-pointer', {
|
47
47
|
'cursor-not-allowed text-grey-dark': props.disabled
|
48
|
-
});
|
49
|
-
|
48
|
+
}, props.className);
|
49
|
+
return createElement("label", {
|
50
50
|
className: labelClassName
|
51
51
|
}, element, label);
|
52
52
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Checkbox.js","sources":["../../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport * as CheckboxPrimitive from '@radix-ui/react-checkbox';\nimport { Icon } from '../Icon/Icon';\n\ntype CheckedState = boolean | 'indeterminate';\n\ntype CheckboxBaseProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'onChange'> & {\n /* Increases visual prominenance of the checkbox */\n highlighted?: boolean;\n /**\n * Indeterminate state should only be used with sub-checkboxes. The indeterminate state is shown if not all\n * sub-checkboxes are selected. This only affects the style, changing the icon in the checkbox.\n */\n indeterminate?: boolean;\n /* Whether the checkbox is in an invalid state */\n invalid?: boolean;\n /** Label for the checkbox */\n label?: React.ReactNode;\n /* Whether user input is required */\n required?: boolean;\n};\n\ninterface UncontrolledCheckboxProps extends CheckboxBaseProps {\n checked?: never;\n onChange?: never;\n /* The default checked state (uncontrolled) */\n defaultChecked?: boolean;\n}\n\ninterface ControlledCheckboxProps extends CheckboxBaseProps {\n defaultChecked?: never;\n /* The current checked state (controlled) */\n checked: boolean;\n /* Handler called when the checked state changes */\n onChange: (checked: boolean) => void;\n}\n\nexport type CheckboxProps = UncontrolledCheckboxProps | ControlledCheckboxProps;\n\nexport const Checkbox = React.forwardRef(function Checkbox(props: CheckboxProps, ref: React.Ref<HTMLButtonElement>) {\n const { checked, highlighted, indeterminate, invalid, label, onChange, ...otherProps } = props;\n\n const className = cn(
|
1
|
+
{"version":3,"file":"Checkbox.js","sources":["../../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport * as CheckboxPrimitive from '@radix-ui/react-checkbox';\nimport { Icon } from '../Icon/Icon';\n\ntype CheckedState = boolean | 'indeterminate';\n\ntype CheckboxBaseProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'onChange'> & {\n /* Increases visual prominenance of the checkbox */\n highlighted?: boolean;\n /**\n * Indeterminate state should only be used with sub-checkboxes. The indeterminate state is shown if not all\n * sub-checkboxes are selected. This only affects the style, changing the icon in the checkbox.\n */\n indeterminate?: boolean;\n /* Whether the checkbox is in an invalid state */\n invalid?: boolean;\n /** Label for the checkbox */\n label?: React.ReactNode;\n /* Whether user input is required */\n required?: boolean;\n};\n\ninterface UncontrolledCheckboxProps extends CheckboxBaseProps {\n checked?: never;\n onChange?: never;\n /* The default checked state (uncontrolled) */\n defaultChecked?: boolean;\n}\n\ninterface ControlledCheckboxProps extends CheckboxBaseProps {\n defaultChecked?: never;\n /* The current checked state (controlled) */\n checked: boolean;\n /* Handler called when the checked state changes */\n onChange: (checked: boolean) => void;\n}\n\nexport type CheckboxProps = UncontrolledCheckboxProps | ControlledCheckboxProps;\n\nexport const Checkbox = React.forwardRef(function Checkbox(props: CheckboxProps, ref: React.Ref<HTMLButtonElement>) {\n const { checked, highlighted, indeterminate, invalid, label, onChange, ...otherProps } = props;\n\n const className = cn('bg-white h-5 w-5 border rounded text-sm flex-shrink-0 self-start mt-[0.1rem]', {\n 'mr-2': !!label,\n 'border-grey-dark text-blue focus:border-blue focus:yt-focus': !props.disabled && !invalid,\n 'border-grey text-blue-light cursor-not-allowed': props.disabled,\n 'bg-[rgba(255,255,0,0.2)] disabled:bg-[rgba(255,255,0,0.075)]': highlighted,\n 'border-red text-red focus:border-red focus:yt-focus-red': invalid && !props.disabled,\n });\n\n let handleChange: ((checked: CheckedState) => void) | undefined;\n\n if (onChange) {\n handleChange = (checked: CheckedState) => onChange(checked === 'indeterminate' ? false : checked);\n }\n\n const element = (\n <CheckboxPrimitive.Root\n {...otherProps}\n data-taco=\"checkbox\"\n checked={indeterminate ? 'indeterminate' : checked}\n className={className}\n onCheckedChange={handleChange}\n ref={ref}\n >\n <CheckboxPrimitive.Indicator className=\"flex h-full w-full\">\n <Icon name={indeterminate ? 'line' : 'tick'} className=\"!h-full !w-full\" />\n </CheckboxPrimitive.Indicator>\n </CheckboxPrimitive.Root>\n );\n\n if (label) {\n const labelClassName = cn(\n 'flex items-center cursor-pointer',\n {\n 'cursor-not-allowed text-grey-dark': props.disabled,\n },\n props.className\n );\n\n return (\n <label className={labelClassName}>\n {element}\n {label}\n </label>\n );\n }\n\n return element;\n});\n"],"names":["Checkbox","React","props","ref","checked","highlighted","indeterminate","invalid","label","onChange","otherProps","className","cn","disabled","handleChange","element","CheckboxPrimitive","onCheckedChange","Icon","name","labelClassName"],"mappings":";;;;;;;IAwCaA,QAAQ,gBAAGC,UAAA,CAAiB,SAASD,QAAT,CAAkBE,KAAlB,EAAwCC,GAAxC;AACrC,MAAQC,OAAR,GAAyFF,KAAzF,CAAQE,OAAR;AAAA,MAAiBC,WAAjB,GAAyFH,KAAzF,CAAiBG,WAAjB;AAAA,MAA8BC,aAA9B,GAAyFJ,KAAzF,CAA8BI,aAA9B;AAAA,MAA6CC,OAA7C,GAAyFL,KAAzF,CAA6CK,OAA7C;AAAA,MAAsDC,KAAtD,GAAyFN,KAAzF,CAAsDM,KAAtD;AAAA,MAA6DC,QAA7D,GAAyFP,KAAzF,CAA6DO,QAA7D;AAAA,MAA0EC,UAA1E,iCAAyFR,KAAzF;;AAEA,MAAMS,SAAS,GAAGC,EAAE,CAAC,8EAAD,EAAiF;AACjG,YAAQ,CAAC,CAACJ,KADuF;AAEjG,mEAA+D,CAACN,KAAK,CAACW,QAAP,IAAmB,CAACN,OAFc;AAGjG,sDAAkDL,KAAK,CAACW,QAHyC;AAIjG,oEAAgER,WAJiC;AAKjG,+DAA2DE,OAAO,IAAI,CAACL,KAAK,CAACW;AALoB,GAAjF,CAApB;AAQA,MAAIC,YAAJ;;AAEA,MAAIL,QAAJ,EAAc;AACVK,IAAAA,YAAY,GAAG,sBAACV,OAAD;AAAA,aAA2BK,QAAQ,CAACL,OAAO,KAAK,eAAZ,GAA8B,KAA9B,GAAsCA,OAAvC,CAAnC;AAAA,KAAf;AACH;;AAED,MAAMW,OAAO,GACTd,aAAA,CAACe,IAAD,oBACQN;iBACM;AACVN,IAAAA,OAAO,EAAEE,aAAa,GAAG,eAAH,GAAqBF;AAC3CO,IAAAA,SAAS,EAAEA;AACXM,IAAAA,eAAe,EAAEH;AACjBX,IAAAA,GAAG,EAAEA;IANT,EAQIF,aAAA,CAACe,SAAD;AAA6BL,IAAAA,SAAS,EAAC;GAAvC,EACIV,aAAA,CAACiB,IAAD;AAAMC,IAAAA,IAAI,EAAEb,aAAa,GAAG,MAAH,GAAY;AAAQK,IAAAA,SAAS,EAAC;GAAvD,CADJ,CARJ,CADJ;;AAeA,MAAIH,KAAJ,EAAW;AACP,QAAMY,cAAc,GAAGR,EAAE,CACrB,kCADqB,EAErB;AACI,2CAAqCV,KAAK,CAACW;AAD/C,KAFqB,EAKrBX,KAAK,CAACS,SALe,CAAzB;AAQA,WACIV,aAAA,QAAA;AAAOU,MAAAA,SAAS,EAAES;KAAlB,EACKL,OADL,EAEKP,KAFL,CADJ;AAMH;;AAED,SAAOO,OAAP;AACH,CAlDuB;;;;"}
|
@@ -49,17 +49,22 @@ var Combobox = /*#__PURE__*/forwardRef(function Combobox(props, ref) {
|
|
49
49
|
className: "!border-l-0 focus:!border-none focus:!shadow-none active:!border-none",
|
50
50
|
icon: popover.open ? 'chevron-up' : 'chevron-down',
|
51
51
|
onClick: function onClick() {
|
52
|
-
|
52
|
+
var _input$ref$current;
|
53
|
+
|
54
|
+
popover.onOpenChange(true);
|
55
|
+
(_input$ref$current = input.ref.current) === null || _input$ref$current === void 0 ? void 0 : _input$ref$current.focus();
|
53
56
|
},
|
54
57
|
tabIndex: -1
|
55
58
|
}) : dialog ? createElement(IconButton, {
|
56
59
|
icon: "list-search",
|
57
60
|
disabled: props.readOnly || props.disabled,
|
58
61
|
dialog: dialog,
|
59
|
-
onFocus: function onFocus() {
|
60
|
-
var _input$ref$
|
62
|
+
onFocus: function onFocus(event) {
|
63
|
+
var _input$ref$current2;
|
61
64
|
|
62
|
-
|
65
|
+
// Prevents the default focus behaviour of showing the tooltip, on parent tooltip element
|
66
|
+
event.preventDefault();
|
67
|
+
(_input$ref$current2 = input.ref.current) === null || _input$ref$current2 === void 0 ? void 0 : _input$ref$current2.focus();
|
63
68
|
},
|
64
69
|
ref: button.ref,
|
65
70
|
tabIndex: -1,
|
@@ -72,7 +77,7 @@ var Combobox = /*#__PURE__*/forwardRef(function Combobox(props, ref) {
|
|
72
77
|
},
|
73
78
|
sideOffset: 4
|
74
79
|
}, createElement(ScrollableList, Object.assign({}, list, {
|
75
|
-
className: cn('border-blue max-h-[calc(12rem+2px)] w-auto max-w-[theme(spacing.96)]'),
|
80
|
+
className: cn('!border-blue max-h-[calc(12rem+2px)] w-auto max-w-[theme(spacing.96)]'),
|
76
81
|
style: {
|
77
82
|
minWidth: selectDimensions === null || selectDimensions === void 0 ? void 0 : selectDimensions.width
|
78
83
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Combobox.js","sources":["../../../../src/components/Combobox/Combobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { Input, InputProps } from '../Input/Input';\nimport { useCombobox } from './useCombobox';\nimport { ScrollableList, ScrollableListItem, ScrollableListItemValue } from '../Listbox/ScrollableList';\nimport { useBoundingClientRectListener } from '../../utils/hooks/useBoundingClientRectListener';\nimport { IconButton } from '../IconButton/IconButton';\nimport './Combobox.css';\nimport { DialogProps } from '../Dialog/Dialog';\nimport { useLocalization } from '../Provider/Provider';\n\nexport type ComboboxTexts = {\n /* Tooltip shown for the dialog button */\n tooltip: string;\n};\n\nexport type ComboboxItem = ScrollableListItem;\nexport type ComboboxValue = ScrollableListItemValue;\n\ntype ComboboxBaseProps = Omit<InputProps, 'defaultValue' | 'button' | 'onChange' | 'value'> & {\n /** Array of options in combobox */\n data?: ComboboxItem[];\n /**\n * Initial value of the input in combobox.\n * This is used when combobox is mounted, if no value is provided.\n * *Note* that combobox is a controlled component, setting this will also trigger the `onChange` event\n */\n defaultValue?: ComboboxValue;\n /** Set what value should have an empty option in combobox */\n emptyValue?: ComboboxValue;\n /** Draws attention to the combobox by changing its style and making it visually prominent */\n highlighted?: boolean;\n /** Displays loading state in listbox */\n loading?: boolean;\n /**\n * Handler called when user chooses an option from the provided suggestions.\n * Suggestions will be calculated based on the input value.\n * There are two ways to choose an option: either click on it, or navigate using keyboard and press `enter`\n */\n onChange?: React.ChangeEventHandler<HTMLInputElement>;\n /** Handler called when the user enters a query **/\n onSearch?: (query: string) => void | Promise<void>;\n /** Value of the input in combobox */\n value?: ComboboxValue;\n};\n\ninterface InlineComboboxProps extends ComboboxBaseProps {\n dialog?: never;\n /**\n * Combobox will display its data when input is clicked/focused, even if the input is empty.\n * *Note* that default combobox will display matching data only when user starts typing in input.\n */\n inline: boolean; // Example 3 on https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html\n}\n\ninterface DialogComboboxProps extends ComboboxBaseProps {\n dialog: (props: Partial<DialogProps>) => JSX.Element;\n inline?: never;\n}\n\nexport type ComboboxProps = InlineComboboxProps | DialogComboboxProps;\n\nexport const Combobox = React.forwardRef(function Combobox(props: ComboboxProps, ref: React.Ref<HTMLInputElement>) {\n const { className: externalClassName, dialog, style, ...otherProps } = props;\n const { combobox, button, input, popover, list } = useCombobox(otherProps, ref);\n const internalRef = React.useRef<HTMLDivElement>(null);\n const { texts } = useLocalization();\n const selectDimensions = useBoundingClientRectListener(internalRef);\n const className = cn(\n 'inline-flex relative',\n {\n 'yt-combobox--inline': props.inline,\n },\n externalClassName\n );\n\n return (\n <span className={className} data-taco=\"combobox\" style={style}>\n <PopoverPrimitive.Root {...popover}>\n <PopoverPrimitive.Anchor asChild ref={internalRef}>\n <div {...combobox} className=\"inline w-full\" ref={ref}>\n <Input\n {...input}\n autoComplete=\"off\"\n button={\n props.inline ? (\n <IconButton\n appearance=\"discrete\"\n className=\"!border-l-0 focus:!border-none focus:!shadow-none active:!border-none\"\n icon={popover.open ? 'chevron-up' : 'chevron-down'}\n onClick={() => popover.onOpenChange(true)}\n tabIndex={-1}\n />\n ) : dialog ? (\n <IconButton\n icon=\"list-search\"\n disabled={props.readOnly || props.disabled}\n dialog={dialog}\n onFocus={() => {\n input.ref.current?.focus();\n }}\n ref={button.ref}\n tabIndex={-1}\n tooltip={texts.combobox.tooltip}\n />\n ) : undefined\n }\n />\n </div>\n </PopoverPrimitive.Anchor>\n <PopoverPrimitive.Content\n align=\"start\"\n onOpenAutoFocus={event => {\n event.preventDefault();\n }}\n sideOffset={4}\n >\n <ScrollableList\n {...list}\n className={cn('border-blue max-h-[calc(12rem+2px)] w-auto max-w-[theme(spacing.96)]')}\n style={{ minWidth: selectDimensions?.width }}\n tabIndex={popover.open ? 0 : -1}\n />\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Root>\n </span>\n );\n});\n"],"names":["Combobox","React","props","ref","externalClassName","className","dialog","style","otherProps","useCombobox","combobox","button","input","popover","list","internalRef","useLocalization","texts","selectDimensions","useBoundingClientRectListener","cn","inline","PopoverPrimitive","asChild","Input","autoComplete","IconButton","appearance","icon","open","onClick","onOpenChange","tabIndex","disabled","readOnly","onFocus","
|
1
|
+
{"version":3,"file":"Combobox.js","sources":["../../../../src/components/Combobox/Combobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport cn from 'classnames';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { Input, InputProps } from '../Input/Input';\nimport { useCombobox } from './useCombobox';\nimport { ScrollableList, ScrollableListItem, ScrollableListItemValue } from '../Listbox/ScrollableList';\nimport { useBoundingClientRectListener } from '../../utils/hooks/useBoundingClientRectListener';\nimport { IconButton } from '../IconButton/IconButton';\nimport './Combobox.css';\nimport { DialogProps } from '../Dialog/Dialog';\nimport { useLocalization } from '../Provider/Provider';\n\nexport type ComboboxTexts = {\n /* Tooltip shown for the dialog button */\n tooltip: string;\n};\n\nexport type ComboboxItem = ScrollableListItem;\nexport type ComboboxValue = ScrollableListItemValue;\n\ntype ComboboxBaseProps = Omit<InputProps, 'defaultValue' | 'button' | 'onChange' | 'value'> & {\n /** Array of options in combobox */\n data?: ComboboxItem[];\n /**\n * Initial value of the input in combobox.\n * This is used when combobox is mounted, if no value is provided.\n * *Note* that combobox is a controlled component, setting this will also trigger the `onChange` event\n */\n defaultValue?: ComboboxValue;\n /** Set what value should have an empty option in combobox */\n emptyValue?: ComboboxValue;\n /** Draws attention to the combobox by changing its style and making it visually prominent */\n highlighted?: boolean;\n /** Displays loading state in listbox */\n loading?: boolean;\n /**\n * Handler called when user chooses an option from the provided suggestions.\n * Suggestions will be calculated based on the input value.\n * There are two ways to choose an option: either click on it, or navigate using keyboard and press `enter`\n */\n onChange?: React.ChangeEventHandler<HTMLInputElement>;\n /** Handler called when the user enters a query **/\n onSearch?: (query: string) => void | Promise<void>;\n /** Value of the input in combobox */\n value?: ComboboxValue;\n};\n\ninterface InlineComboboxProps extends ComboboxBaseProps {\n dialog?: never;\n /**\n * Combobox will display its data when input is clicked/focused, even if the input is empty.\n * *Note* that default combobox will display matching data only when user starts typing in input.\n */\n inline: boolean; // Example 3 on https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html\n}\n\ninterface DialogComboboxProps extends ComboboxBaseProps {\n dialog: (props: Partial<DialogProps>) => JSX.Element;\n inline?: never;\n}\n\nexport type ComboboxProps = InlineComboboxProps | DialogComboboxProps;\n\nexport const Combobox = React.forwardRef(function Combobox(props: ComboboxProps, ref: React.Ref<HTMLInputElement>) {\n const { className: externalClassName, dialog, style, ...otherProps } = props;\n const { combobox, button, input, popover, list } = useCombobox(otherProps, ref);\n const internalRef = React.useRef<HTMLDivElement>(null);\n const { texts } = useLocalization();\n const selectDimensions = useBoundingClientRectListener(internalRef);\n const className = cn(\n 'inline-flex relative',\n {\n 'yt-combobox--inline': props.inline,\n },\n externalClassName\n );\n\n return (\n <span className={className} data-taco=\"combobox\" style={style}>\n <PopoverPrimitive.Root {...popover}>\n <PopoverPrimitive.Anchor asChild ref={internalRef}>\n <div {...combobox} className=\"inline w-full\" ref={ref}>\n <Input\n {...input}\n autoComplete=\"off\"\n button={\n props.inline ? (\n <IconButton\n appearance=\"discrete\"\n className=\"!border-l-0 focus:!border-none focus:!shadow-none active:!border-none\"\n icon={popover.open ? 'chevron-up' : 'chevron-down'}\n onClick={() => {\n popover.onOpenChange(true);\n input.ref.current?.focus();\n }}\n tabIndex={-1}\n />\n ) : dialog ? (\n <IconButton\n icon=\"list-search\"\n disabled={props.readOnly || props.disabled}\n dialog={dialog}\n onFocus={(event: React.FocusEvent<HTMLButtonElement>) => {\n // Prevents the default focus behaviour of showing the tooltip, on parent tooltip element\n event.preventDefault();\n input.ref.current?.focus();\n }}\n ref={button.ref}\n tabIndex={-1}\n tooltip={texts.combobox.tooltip}\n />\n ) : undefined\n }\n />\n </div>\n </PopoverPrimitive.Anchor>\n <PopoverPrimitive.Content\n align=\"start\"\n onOpenAutoFocus={event => {\n event.preventDefault();\n }}\n sideOffset={4}\n >\n <ScrollableList\n {...list}\n className={cn('!border-blue max-h-[calc(12rem+2px)] w-auto max-w-[theme(spacing.96)]')}\n style={{ minWidth: selectDimensions?.width }}\n tabIndex={popover.open ? 0 : -1}\n />\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Root>\n </span>\n );\n});\n"],"names":["Combobox","React","props","ref","externalClassName","className","dialog","style","otherProps","useCombobox","combobox","button","input","popover","list","internalRef","useLocalization","texts","selectDimensions","useBoundingClientRectListener","cn","inline","PopoverPrimitive","asChild","Input","autoComplete","IconButton","appearance","icon","open","onClick","onOpenChange","current","focus","tabIndex","disabled","readOnly","onFocus","event","preventDefault","tooltip","undefined","align","onOpenAutoFocus","sideOffset","ScrollableList","minWidth","width"],"mappings":";;;;;;;;;;;;IA+DaA,QAAQ,gBAAGC,UAAA,CAAiB,SAASD,QAAT,CAAkBE,KAAlB,EAAwCC,GAAxC;AACrC,MAAmBC,iBAAnB,GAAuEF,KAAvE,CAAQG,SAAR;AAAA,MAAsCC,MAAtC,GAAuEJ,KAAvE,CAAsCI,MAAtC;AAAA,MAA8CC,KAA9C,GAAuEL,KAAvE,CAA8CK,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T,GAAN,CAAU6B,OAAV,0EAAmBC,KAAnB;AACH;AACDC,MAAAA,QAAQ,EAAE,CAAC;KARf,CADJ,GAWI5B,MAAM,GACNL,aAAA,CAACyB,UAAD;AACIE,MAAAA,IAAI,EAAC;AACLO,MAAAA,QAAQ,EAAEjC,KAAK,CAACkC,QAAN,IAAkBlC,KAAK,CAACiC;AAClC7B,MAAAA,MAAM,EAAEA;AACR+B,MAAAA,OAAO,EAAE,iBAACC,KAAD;;;AACL;AACAA,QAAAA,KAAK,CAACC,cAAN;AACA,+BAAA3B,KAAK,CAACT,GAAN,CAAU6B,OAAV,4EAAmBC,KAAnB;AACH;AACD9B,MAAAA,GAAG,EAAEQ,MAAM,CAACR;AACZ+B,MAAAA,QAAQ,EAAE,CAAC;AACXM,MAAAA,OAAO,EAAEvB,KAAK,CAACP,QAAN,CAAe8B;KAX5B,CADM,GAcNC;IA7BZ,CADJ,CADJ,CADJ,EAqCIxC,aAAA,CAACqB,OAAD;AACIoB,IAAAA,KAAK,EAAC;AACNC,IAAAA,eAAe,EAAE,yBAAAL,KAAK;AAClBA,MAAAA,KAAK,CAACC,cAAN;AACH;AACDK,IAAAA,UAAU,EAAE;GALhB,EAOI3C,aAAA,CAAC4C,cAAD,oBACQ/B;AACJT,IAAAA,SAAS,EAAEe,EAAE,CAAC,uEAAD;AACbb,IAAAA,KAAK,EAAE;AAAEuC,MAAAA,QAAQ,EAAE5B,gBAAF,aAAEA,gBAAF,uBAAEA,gBAAgB,CAAE6B;AAA9B;AACPb,IAAAA,QAAQ,EAAErB,OAAO,CAACgB,IAAR,GAAe,CAAf,GAAmB,CAAC;IAJlC,CAPJ,CArCJ,CADJ,CADJ;AAwDH,CAtEuB;;;;"}
|
@@ -8,7 +8,7 @@ import { getId } from '../Listbox/ScrollableList.js';
|
|
8
8
|
import { createCustomKeyboardEvent } from '../../utils/input.js';
|
9
9
|
import { useFlattenedData, filterData, getIndexFromValue, setInputValueByRef, findByValue, sanitizeItem, getOptionParents } from '../Listbox/util.js';
|
10
10
|
|
11
|
-
var _excluded = ["aria-label", "aria-labelledby", "data", "defaultValue", "disabled", "inline", "loading", "onChange", "onClick", "onKeyDown", "onSearch", "readOnly", "value"];
|
11
|
+
var _excluded = ["aria-label", "aria-labelledby", "data", "defaultValue", "disabled", "id", "inline", "loading", "onChange", "onClick", "onKeyDown", "onSearch", "readOnly", "value"];
|
12
12
|
var debouncer = /*#__PURE__*/debounce(function (f) {
|
13
13
|
return f();
|
14
14
|
}, 200);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useCombobox.js","sources":["../../../../src/components/Combobox/useCombobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport keycode from 'keycode';\nimport { v4 as uuid } from 'uuid';\nimport debounce from 'lodash/debounce';\nimport { ComboboxProps } from './Combobox';\nimport {\n setInputValueByRef,\n getIndexFromValue,\n findByValue,\n useFlattenedData,\n sanitizeItem,\n getOptionParents,\n filterData,\n} from '../Listbox/util';\nimport { createCustomKeyboardEvent } from '../../utils/input';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport { getId, ScrollableListItemValue, ScrollableListPropsWithRef } from '../Listbox/ScrollableList';\n\nconst debouncer = debounce(f => f(), 200);\n\nconst convertToInputValue = (value: ScrollableListItemValue | undefined) => String(value ?? '');\n\ntype useCombobox = React.HTMLAttributes<HTMLDivElement> & {\n combobox: React.HTMLAttributes<HTMLSpanElement>;\n input: Omit<React.InputHTMLAttributes<HTMLInputElement>, 'defaultValue'> & { ref: React.RefObject<HTMLInputElement> };\n list: ScrollableListPropsWithRef;\n button: { ref: any };\n popover: { open: boolean; onOpenChange: (open: boolean) => void };\n};\n\nexport const useCombobox = (\n {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data: unfilteredData = [],\n defaultValue,\n disabled,\n inline,\n loading: __,\n onChange,\n onClick,\n onKeyDown,\n onSearch,\n readOnly,\n value,\n ...props\n }: Omit<ComboboxProps, 'dialog'>,\n ref: React.Ref<HTMLInputElement>\n): useCombobox => {\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n const listRef = React.useRef<HTMLUListElement>(null);\n const [open, setOpen] = React.useState(false);\n const listId = React.useMemo(() => uuid(), []);\n const [inputValue, setInputValue] = React.useState<string>(convertToInputValue(value));\n const shouldFilterData = !onSearch && (!inline || (inline && inputValue !== convertToInputValue(value)));\n const flattenedData = useFlattenedData(unfilteredData);\n const data = React.useMemo(\n () => (shouldFilterData ? filterData(flattenedData, inputValue) : flattenedData),\n [shouldFilterData, inputValue, flattenedData]\n );\n // listbox/select change value _with_ the index, but combobox changes on select of an index (click/enter), so we need state\n const [currentIndex, setCurrentIndex] = React.useState<number | undefined>(\n inputValue !== undefined ? getIndexFromValue(data, inputValue) : undefined\n );\n\n const setInputValueByIndex = (index: number | undefined): void => {\n if (index !== undefined) {\n const option = data[index];\n\n if (option && !option.disabled) {\n setInputValueByRef(inputRef.current, option.value, 'focusout');\n }\n }\n };\n\n const setCurrentValue = (index: number | undefined) => {\n if (index === undefined) {\n return;\n }\n\n const option = data[index];\n\n // if the selected option is not already selected, trigger blur event\n if (option.value !== value) {\n setInputValueByIndex(index);\n } else {\n // if the selected option is already selected, refill input with its value\n setInputValue(convertToInputValue(value));\n }\n };\n\n // ensure the external value is synced with the internal value when mounting, e.g. incase a default value was set\n React.useEffect(() => {\n if (defaultValue && !value) {\n setInputValueByIndex(getIndexFromValue(data, defaultValue));\n }\n }, [data]);\n\n // update input value if it changed 'externally', e.g. clicking/entering an item in the listbox, from a modal etc\n React.useEffect(() => {\n if (value !== undefined && value !== inputValue) {\n setInputValue(convertToInputValue(value));\n }\n }, [value]);\n\n React.useEffect(() => {\n if (onSearch) {\n debouncer(() => {\n onSearch(inputValue);\n });\n }\n }, [inputValue]);\n\n // show listbox based on input value\n React.useEffect(() => {\n // don't show the popover if the internal (input) value already is the current value\n // this prevents the popover showing after selecting a value or pressing escape\n const isCurrentValue = value !== undefined && value !== null && inputValue === String(value);\n\n if (inputValue && data.length && !isCurrentValue) {\n setCurrentIndex(0);\n\n if (!open) {\n setOpen(true);\n }\n } else {\n setOpen(false);\n }\n }, [inputValue, data]);\n\n React.useEffect(() => {\n if (open) {\n setCurrentIndex(getIndexFromValue(data, inputValue) || 0);\n } else {\n setCurrentIndex(undefined);\n }\n }, [open]);\n\n // event handlers\n const handleInputBlur = (event: React.FocusEvent<HTMLInputElement>): void => {\n event.persist();\n\n if (event.relatedTarget === listRef.current) {\n event.preventDefault();\n return;\n }\n\n if (onChange && event.target.value !== value) {\n const item = findByValue(flattenedData, event.target.value);\n (event as any).detail = sanitizeItem(item);\n\n const parents = getOptionParents(flattenedData, item?.path);\n\n if (parents !== null && parents.length > 0) {\n (event as any).detail.parents = parents;\n }\n\n onChange(event);\n }\n\n if (props.onBlur) {\n props.onBlur(event);\n }\n };\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n setInputValue(event.target.value);\n };\n\n const handleInputClick = (event: React.MouseEvent<HTMLInputElement>): void => {\n if (inline || (!open && inputValue && data.length)) {\n setOpen(true);\n }\n\n if (onClick) {\n event.persist();\n onClick(event);\n }\n };\n\n const handleInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>): void => {\n event.persist();\n\n switch (event.keyCode) {\n case keycode('backspace'): {\n return;\n }\n\n case keycode('escape'): {\n event.preventDefault();\n setInputValue(convertToInputValue(value));\n setOpen(false);\n return;\n }\n\n case keycode('tab'):\n case keycode('enter'): {\n if (event.keyCode !== keycode('tab')) {\n event.preventDefault();\n }\n\n setCurrentValue(currentIndex);\n setOpen(false);\n return;\n }\n\n case keycode('down'):\n if (open) {\n event.preventDefault();\n } else {\n if (!inline && buttonRef.current) {\n buttonRef.current.click();\n }\n }\n break;\n\n case keycode('up'):\n case keycode('home'):\n case keycode('end'): {\n if (open) {\n event.preventDefault();\n }\n break;\n }\n\n default:\n }\n\n // we aren't focused on the list, so manually forward the keydown event to it\n if (listRef.current) {\n listRef.current.dispatchEvent(createCustomKeyboardEvent(event));\n }\n\n if (inline && !open) {\n if (event.keyCode === keycode('up') || event.keyCode === keycode('down')) {\n event.preventDefault();\n const initialIndex = event.keyCode === keycode('up') ? data.length - 1 : 0;\n setCurrentIndex(currentIndex !== undefined ? currentIndex : initialIndex);\n setOpen(true);\n }\n }\n\n if (!event.isDefaultPrevented() && onKeyDown) {\n event.persist();\n onKeyDown(event);\n }\n };\n\n const handleListboxChange = (index: number): void => {\n setCurrentIndex(index);\n };\n\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>, index: number): void => {\n event.preventDefault();\n setCurrentValue(index);\n setOpen(false);\n };\n\n const combobox = {\n 'aria-expanded': open,\n 'aria-owns': listId,\n 'aria-haspopup': 'listbox' as const,\n role: 'combobox',\n };\n\n const input = {\n ...props,\n 'aria-controls': listId,\n // Indicates that the autocomplete behavior of the text input is to suggest a list of possible values in a popup and that the suggestions\n // are related to the string that is present in the textbox\n 'aria-autocomplete': 'list' as const,\n // Enables assistive technologies to know which element the application regards as focused while DOM focus remains on the input element\n 'aria-activedescendant':\n currentIndex !== undefined && data[currentIndex] ? getId(listId, String(data[currentIndex].value)) : undefined,\n 'aria-labelledby': ariaLabelledBy,\n disabled,\n onBlur: !disabled && !readOnly ? handleInputBlur : undefined,\n onChange: !disabled && !readOnly ? handleInputChange : undefined,\n onClick: !disabled && !readOnly ? handleInputClick : undefined,\n onKeyDown: !disabled && !readOnly ? handleInputKeyDown : undefined,\n readOnly,\n ref: inputRef,\n type: 'text',\n value: inputValue ?? '',\n };\n\n const list: ScrollableListPropsWithRef = {\n 'aria-labelledby': ariaLabelledBy,\n data,\n disabled,\n id: listId,\n onChange: handleListboxChange,\n onClick: handleListboxClick,\n ref: listRef,\n scrollOnFocus: false,\n tabIndex: -1,\n value: currentIndex,\n };\n\n const button = {\n ref: buttonRef,\n };\n\n return {\n combobox,\n input,\n list,\n button,\n popover: {\n open,\n onOpenChange: setOpen,\n //visible: !data.length ? false : open,\n },\n };\n};\n"],"names":["debouncer","debounce","f","convertToInputValue","value","String","useCombobox","ref","ariaLabelledBy","data","unfilteredData","defaultValue","disabled","inline","onChange","onClick","onKeyDown","onSearch","readOnly","props","inputRef","useProxiedRef","buttonRef","React","listRef","open","setOpen","listId","uuid","inputValue","setInputValue","shouldFilterData","flattenedData","useFlattenedData","filterData","undefined","getIndexFromValue","currentIndex","setCurrentIndex","setInputValueByIndex","index","option","setInputValueByRef","current","setCurrentValue","isCurrentValue","length","handleInputBlur","event","persist","relatedTarget","preventDefault","target","item","findByValue","detail","sanitizeItem","parents","getOptionParents","path","onBlur","handleInputChange","handleInputClick","handleInputKeyDown","keyCode","keycode","click","dispatchEvent","createCustomKeyboardEvent","initialIndex","isDefaultPrevented","handleListboxChange","handleListboxClick","combobox","role","input","getId","type","list","id","scrollOnFocus","tabIndex","button","popover","onOpenChange"],"mappings":";;;;;;;;;;;AAkBA,IAAMA,SAAS,gBAAGC,QAAQ,CAAC,UAAAC,CAAC;AAAA,SAAIA,CAAC,EAAL;AAAA,CAAF,EAAW,GAAX,CAA1B;;AAEA,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACC,KAAD;AAAA,SAAgDC,MAAM,CAACD,KAAD,aAACA,KAAD,cAACA,KAAD,GAAU,EAAV,CAAtD;AAAA,CAA5B;;IAUaE,WAAW,GAAG,SAAdA,WAAc,OAiBvBC,GAjBuB;MAGAC,sBAAnB;uBACAC;MAAMC,wCAAiB;MACvBC,oBAAAA;MACAC,gBAAAA;MACAC,cAAAA;MAEAC,gBAAAA;MACAC,eAAAA;MACAC,iBAAAA;MACAC,gBAAAA;MACAC,gBAAAA;MACAd,aAAAA;MACGe;;AAIP,MAAMC,QAAQ,GAAGC,aAAa,CAAmBd,GAAnB,CAA9B;AACA,MAAMe,SAAS,GAAGC,MAAA,CAAgC,IAAhC,CAAlB;AACA,MAAMC,OAAO,GAAGD,MAAA,CAA+B,IAA/B,CAAhB;;AACA,wBAAwBA,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IAAI,EAAJA,IAFqC;AAGrCG,IAAAA,QAAQ,EAARA,QAHqC;AAIrCmE,IAAAA,EAAE,EAAEpD,MAJiC;AAKrCb,IAAAA,QAAQ,EAAEyD,mBAL2B;AAMrCxD,IAAAA,OAAO,EAAEyD,kBAN4B;AAOrCjE,IAAAA,GAAG,EAAEiB,OAPgC;AAQrCwD,IAAAA,aAAa,EAAE,KARsB;AASrCC,IAAAA,QAAQ,EAAE,CAAC,CAT0B;AAUrC7E,IAAAA,KAAK,EAAEiC;AAV8B,GAAzC;AAaA,MAAM6C,MAAM,GAAG;AACX3E,IAAAA,GAAG,EAAEe;AADM,GAAf;AAIA,SAAO;AACHmD,IAAAA,QAAQ,EAARA,QADG;AAEHE,IAAAA,KAAK,EAALA,KAFG;AAGHG,IAAAA,IAAI,EAAJA,IAHG;AAIHI,IAAAA,MAAM,EAANA,MAJG;AAKHC,IAAAA,OAAO,EAAE;AACL1D,MAAAA,IAAI,EAAJA,IADK;AAEL2D,MAAAA,YAAY,EAAE1D;AAFT;AALN,GAAP;AAWH;;;;"}
|
1
|
+
{"version":3,"file":"useCombobox.js","sources":["../../../../src/components/Combobox/useCombobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport keycode from 'keycode';\nimport { v4 as uuid } from 'uuid';\nimport debounce from 'lodash/debounce';\nimport { ComboboxProps } from './Combobox';\nimport {\n setInputValueByRef,\n getIndexFromValue,\n findByValue,\n useFlattenedData,\n sanitizeItem,\n getOptionParents,\n filterData,\n} from '../Listbox/util';\nimport { createCustomKeyboardEvent } from '../../utils/input';\nimport { useProxiedRef } from '../../utils/hooks/useProxiedRef';\nimport { getId, ScrollableListItemValue, ScrollableListPropsWithRef } from '../Listbox/ScrollableList';\n\nconst debouncer = debounce(f => f(), 200);\n\nconst convertToInputValue = (value: ScrollableListItemValue | undefined) => String(value ?? '');\n\ntype useCombobox = React.HTMLAttributes<HTMLDivElement> & {\n combobox: React.HTMLAttributes<HTMLSpanElement>;\n input: Omit<React.InputHTMLAttributes<HTMLInputElement>, 'defaultValue'> & { ref: React.RefObject<HTMLInputElement> };\n list: ScrollableListPropsWithRef;\n button: { ref: any };\n popover: { open: boolean; onOpenChange: (open: boolean) => void };\n};\n\nexport const useCombobox = (\n {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n data: unfilteredData = [],\n defaultValue,\n disabled,\n id: nativeId,\n inline,\n loading: __,\n onChange,\n onClick,\n onKeyDown,\n onSearch,\n readOnly,\n value,\n ...props\n }: Omit<ComboboxProps, 'dialog'>,\n ref: React.Ref<HTMLInputElement>\n): useCombobox => {\n const inputRef = useProxiedRef<HTMLInputElement>(ref);\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n const listRef = React.useRef<HTMLUListElement>(null);\n const [open, setOpen] = React.useState(false);\n const listId = React.useMemo(() => uuid(), []);\n const [inputValue, setInputValue] = React.useState<string>(convertToInputValue(value));\n const shouldFilterData = !onSearch && (!inline || (inline && inputValue !== convertToInputValue(value)));\n const flattenedData = useFlattenedData(unfilteredData);\n const data = React.useMemo(\n () => (shouldFilterData ? filterData(flattenedData, inputValue) : flattenedData),\n [shouldFilterData, inputValue, flattenedData]\n );\n // listbox/select change value _with_ the index, but combobox changes on select of an index (click/enter), so we need state\n const [currentIndex, setCurrentIndex] = React.useState<number | undefined>(\n inputValue !== undefined ? getIndexFromValue(data, inputValue) : undefined\n );\n\n const setInputValueByIndex = (index: number | undefined): void => {\n if (index !== undefined) {\n const option = data[index];\n\n if (option && !option.disabled) {\n setInputValueByRef(inputRef.current, option.value, 'focusout');\n }\n }\n };\n\n const setCurrentValue = (index: number | undefined) => {\n if (index === undefined) {\n return;\n }\n\n const option = data[index];\n\n // if the selected option is not already selected, trigger blur event\n if (option.value !== value) {\n setInputValueByIndex(index);\n } else {\n // if the selected option is already selected, refill input with its value\n setInputValue(convertToInputValue(value));\n }\n };\n\n // ensure the external value is synced with the internal value when mounting, e.g. incase a default value was set\n React.useEffect(() => {\n if (defaultValue && !value) {\n setInputValueByIndex(getIndexFromValue(data, defaultValue));\n }\n }, [data]);\n\n // update input value if it changed 'externally', e.g. clicking/entering an item in the listbox, from a modal etc\n React.useEffect(() => {\n if (value !== undefined && value !== inputValue) {\n setInputValue(convertToInputValue(value));\n }\n }, [value]);\n\n React.useEffect(() => {\n if (onSearch) {\n debouncer(() => {\n onSearch(inputValue);\n });\n }\n }, [inputValue]);\n\n // show listbox based on input value\n React.useEffect(() => {\n // don't show the popover if the internal (input) value already is the current value\n // this prevents the popover showing after selecting a value or pressing escape\n const isCurrentValue = value !== undefined && value !== null && inputValue === String(value);\n\n if (inputValue && data.length && !isCurrentValue) {\n setCurrentIndex(0);\n\n if (!open) {\n setOpen(true);\n }\n } else {\n setOpen(false);\n }\n }, [inputValue, data]);\n\n React.useEffect(() => {\n if (open) {\n setCurrentIndex(getIndexFromValue(data, inputValue) || 0);\n } else {\n setCurrentIndex(undefined);\n }\n }, [open]);\n\n // event handlers\n const handleInputBlur = (event: React.FocusEvent<HTMLInputElement>): void => {\n event.persist();\n\n if (event.relatedTarget === listRef.current) {\n event.preventDefault();\n return;\n }\n\n if (onChange && event.target.value !== value) {\n const item = findByValue(flattenedData, event.target.value);\n (event as any).detail = sanitizeItem(item);\n\n const parents = getOptionParents(flattenedData, item?.path);\n\n if (parents !== null && parents.length > 0) {\n (event as any).detail.parents = parents;\n }\n\n onChange(event);\n }\n\n if (props.onBlur) {\n props.onBlur(event);\n }\n };\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>): void => {\n setInputValue(event.target.value);\n };\n\n const handleInputClick = (event: React.MouseEvent<HTMLInputElement>): void => {\n if (inline || (!open && inputValue && data.length)) {\n setOpen(true);\n }\n\n if (onClick) {\n event.persist();\n onClick(event);\n }\n };\n\n const handleInputKeyDown = (event: React.KeyboardEvent<HTMLInputElement>): void => {\n event.persist();\n\n switch (event.keyCode) {\n case keycode('backspace'): {\n return;\n }\n\n case keycode('escape'): {\n event.preventDefault();\n setInputValue(convertToInputValue(value));\n setOpen(false);\n return;\n }\n\n case keycode('tab'):\n case keycode('enter'): {\n if (event.keyCode !== keycode('tab')) {\n event.preventDefault();\n }\n\n setCurrentValue(currentIndex);\n setOpen(false);\n return;\n }\n\n case keycode('down'):\n if (open) {\n event.preventDefault();\n } else {\n if (!inline && buttonRef.current) {\n buttonRef.current.click();\n }\n }\n break;\n\n case keycode('up'):\n case keycode('home'):\n case keycode('end'): {\n if (open) {\n event.preventDefault();\n }\n break;\n }\n\n default:\n }\n\n // we aren't focused on the list, so manually forward the keydown event to it\n if (listRef.current) {\n listRef.current.dispatchEvent(createCustomKeyboardEvent(event));\n }\n\n if (inline && !open) {\n if (event.keyCode === keycode('up') || event.keyCode === keycode('down')) {\n event.preventDefault();\n const initialIndex = event.keyCode === keycode('up') ? data.length - 1 : 0;\n setCurrentIndex(currentIndex !== undefined ? currentIndex : initialIndex);\n setOpen(true);\n }\n }\n\n if (!event.isDefaultPrevented() && onKeyDown) {\n event.persist();\n onKeyDown(event);\n }\n };\n\n const handleListboxChange = (index: number): void => {\n setCurrentIndex(index);\n };\n\n const handleListboxClick = (event: React.MouseEvent<HTMLLIElement>, index: number): void => {\n event.preventDefault();\n setCurrentValue(index);\n setOpen(false);\n };\n\n const combobox = {\n 'aria-expanded': open,\n 'aria-owns': listId,\n 'aria-haspopup': 'listbox' as const,\n role: 'combobox',\n };\n\n const input = {\n ...props,\n 'aria-controls': listId,\n // Indicates that the autocomplete behavior of the text input is to suggest a list of possible values in a popup and that the suggestions\n // are related to the string that is present in the textbox\n 'aria-autocomplete': 'list' as const,\n // Enables assistive technologies to know which element the application regards as focused while DOM focus remains on the input element\n 'aria-activedescendant':\n currentIndex !== undefined && data[currentIndex] ? getId(listId, String(data[currentIndex].value)) : undefined,\n 'aria-labelledby': ariaLabelledBy,\n disabled,\n onBlur: !disabled && !readOnly ? handleInputBlur : undefined,\n onChange: !disabled && !readOnly ? handleInputChange : undefined,\n onClick: !disabled && !readOnly ? handleInputClick : undefined,\n onKeyDown: !disabled && !readOnly ? handleInputKeyDown : undefined,\n readOnly,\n ref: inputRef,\n type: 'text',\n value: inputValue ?? '',\n };\n\n const list: ScrollableListPropsWithRef = {\n 'aria-labelledby': ariaLabelledBy,\n data,\n disabled,\n id: listId,\n onChange: handleListboxChange,\n onClick: handleListboxClick,\n ref: listRef,\n scrollOnFocus: false,\n tabIndex: -1,\n value: currentIndex,\n };\n\n const button = {\n ref: buttonRef,\n };\n\n return {\n combobox,\n input,\n list,\n button,\n popover: {\n open,\n onOpenChange: setOpen,\n //visible: !data.length ? false : open,\n },\n };\n};\n"],"names":["debouncer","debounce","f","convertToInputValue","value","String","useCombobox","ref","ariaLabelledBy","data","unfilteredData","defaultValue","disabled","inline","onChange","onClick","onKeyDown","onSearch","readOnly","props","inputRef","useProxiedRef","buttonRef","React","listRef","open","setOpen","listId","uuid","inputValue","setInputValue","shouldFilterData","flattenedData","useFlattenedData","filterData","undefined","getIndexFromValue","currentIndex","setCurrentIndex","setInputValueByIndex","index","option","setInputValueByRef","current","setCurrentValue","isCurrentValue","length","handleInputBlur","event","persist","relatedTarget","preventDefault","target","item","findByValue","detail","sanitizeItem","parents","getOptionParents","path","onBlur","handleInputChange","handleInputClick","handleInputKeyDown","keyCode","keycode","click","dispatchEvent","createCustomKeyboardEvent","initialIndex","isDefaultPrevented","handleListboxChange","handleListboxClick","combobox","role","input","getId","type","list","id","scrollOnFocus","tabIndex","button","popover","onOpenChange"],"mappings":";;;;;;;;;;;AAkBA,IAAMA,SAAS,gBAAGC,QAAQ,CAAC,UAAAC,CAAC;AAAA,SAAIA,CAAC,EAAL;AAAA,CAAF,EAAW,GAAX,CAA1B;;AAEA,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACC,KAAD;AAAA,SAAgDC,MAAM,CAACD,KAAD,aAACA,KAAD,cAACA,KAAD,GAAU,EAAV,CAAtD;AAAA,CAA5B;;IAUaE,WAAW,GAAG,SAAdA,WAAc,OAkBvBC,GAlBuB;MAGAC,s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B,IAAAA,SAAS,EAAE,CAACJ,QAAD,IAAa,CAACM,QAAd,GAAyB6C,kBAAzB,GAA8C5B,SAdlD;AAePjB,IAAAA,QAAQ,EAARA,QAfO;AAgBPX,IAAAA,GAAG,EAAEa,QAhBE;AAiBPyD,IAAAA,IAAI,EAAE,MAjBC;AAkBPzE,IAAAA,KAAK,EAAEyB,UAAF,aAAEA,UAAF,cAAEA,UAAF,GAAgB;AAlBd,IAAX;;AAqBA,MAAMiD,IAAI,GAA+B;AACrC,uBAAmBtE,cADkB;AAErCC,IAAAA,IAAI,EAAJA,IAFqC;AAGrCG,IAAAA,QAAQ,EAARA,QAHqC;AAIrCmE,IAAAA,EAAE,EAAEpD,MAJiC;AAKrCb,IAAAA,QAAQ,EAAEyD,mBAL2B;AAMrCxD,IAAAA,OAAO,EAAEyD,kBAN4B;AAOrCjE,IAAAA,GAAG,EAAEiB,OAPgC;AAQrCwD,IAAAA,aAAa,EAAE,KARsB;AASrCC,IAAAA,QAAQ,EAAE,CAAC,CAT0B;AAUrC7E,IAAAA,KAAK,EAAEiC;AAV8B,GAAzC;AAaA,MAAM6C,MAAM,GAAG;AACX3E,IAAAA,GAAG,EAAEe;AADM,GAAf;AAIA,SAAO;AACHmD,IAAAA,QAAQ,EAARA,QADG;AAEHE,IAAAA,KAAK,EAALA,KAFG;AAGHG,IAAAA,IAAI,EAAJA,IAHG;AAIHI,IAAAA,MAAM,EAANA,MAJG;AAKHC,IAAAA,OAAO,EAAE;AACL1D,MAAAA,IAAI,EAAJA,IADK;AAEL2D,MAAAA,YAAY,EAAE1D;AAFT;AALN,GAAP;AAWH;;;;"}
|
@@ -1,53 +1,31 @@
|
|
1
1
|
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
2
|
-
import { forwardRef,
|
2
|
+
import { forwardRef, createElement } from 'react';
|
3
3
|
import cn from 'classnames';
|
4
|
-
import { v4 } from 'uuid';
|
5
4
|
|
6
|
-
var _excluded = ["
|
5
|
+
var _excluded = ["disabled", "children", "invalid", "message"];
|
7
6
|
var Field = /*#__PURE__*/forwardRef(function Field(props, ref) {
|
8
|
-
var
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
invalid = props.invalid,
|
13
|
-
label = props.label,
|
7
|
+
var disabled = props.disabled,
|
8
|
+
children = props.children,
|
9
|
+
_props$invalid = props.invalid,
|
10
|
+
invalid = _props$invalid === void 0 ? false : _props$invalid,
|
14
11
|
message = props.message,
|
15
|
-
required = props.required,
|
16
12
|
otherProps = _objectWithoutPropertiesLoose(props, _excluded);
|
17
13
|
|
18
|
-
var
|
19
|
-
var isInvalid = (_children$props$inval = children === null || children === void 0 ? void 0 : (_children$props2 = children.props) === null || _children$props2 === void 0 ? void 0 : _children$props2.invalid) !== null && _children$props$inval !== void 0 ? _children$props$inval : invalid;
|
20
|
-
var isRequired = (_children$props$requi = children === null || children === void 0 ? void 0 : (_children$props3 = children.props) === null || _children$props3 === void 0 ? void 0 : _children$props3.required) !== null && _children$props$requi !== void 0 ? _children$props$requi : required;
|
21
|
-
var className = cn('flex flex-col', {
|
22
|
-
'pt-5': !label,
|
23
|
-
'mb-4': !message
|
24
|
-
}, props.className);
|
25
|
-
var labelClassName = cn('font-bold text-xs leading-4 h-4 truncate mb-1', {
|
14
|
+
var className = cn('flex flex-col font-bold text-xs leading-loose pb-4 min-h-[theme(spacing.18)]', {
|
26
15
|
'text-grey-dark': disabled
|
27
|
-
});
|
28
|
-
var messageClassName = cn('text-xs leading-normal truncate
|
29
|
-
'text-grey-darkest': !
|
30
|
-
'text-red':
|
16
|
+
}, props.className);
|
17
|
+
var messageClassName = cn('h-4 text-xs text-left leading-normal font-normal truncate -mb-4', {
|
18
|
+
'text-grey-darkest': !invalid,
|
19
|
+
'text-red': invalid,
|
31
20
|
'opacity-50': disabled
|
32
|
-
});
|
33
|
-
|
34
|
-
if (!label && !(children !== null && children !== void 0 && children.props['aria-label'])) {
|
35
|
-
console.warn('TACO - You are creating a Field without a `label`, you must pass an `aria-label` to the Field child to provide an accessible experience for our users.');
|
36
|
-
}
|
37
|
-
|
38
|
-
return createElement("div", Object.assign({}, otherProps, {
|
21
|
+
}, props.className);
|
22
|
+
return createElement("label", Object.assign({}, otherProps, {
|
39
23
|
className: className,
|
40
|
-
"data-taco": "
|
24
|
+
"data-taco": "label",
|
41
25
|
ref: ref
|
42
|
-
}),
|
43
|
-
htmlFor: idRef.current,
|
44
|
-
className: labelClassName,
|
45
|
-
"data-taco": "label"
|
46
|
-
}, label, isRequired ? '*' : ''), idRef.current !== (children === null || children === void 0 ? void 0 : (_children$props4 = children.props) === null || _children$props4 === void 0 ? void 0 : _children$props4.id) ? cloneElement(children, {
|
47
|
-
id: idRef.current
|
48
|
-
}) : children, message && createElement("span", {
|
26
|
+
}), children, message && createElement("span", {
|
49
27
|
className: messageClassName,
|
50
|
-
role:
|
28
|
+
role: invalid ? 'alert' : undefined
|
51
29
|
}, message));
|
52
30
|
});
|
53
31
|
|