@parrot-co/parrot-ui 1.0.0-beta.1 → 1.0.0-beta.2

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/index.d.mts CHANGED
@@ -135,6 +135,45 @@ type NumberInputProps = Omit<NumberFieldProps, "className" | "style" | "children
135
135
  };
136
136
  declare function NumberInput({ appearance, size, color, classNames, styles, append, prepend, placeholder, showSteppers, error, label, description, incrementIcon, decrementIcon, inputRef, wrapperRef, validationStatus, shape, radius, ...props }: NumberInputProps): React$1.JSX.Element;
137
137
 
138
+ type PinInputType = "numeric" | "alphanumeric" | "all";
139
+ type PinInputProps = Omit<FieldComponentProps<"input" | "control" | "group" | "slot">, "prepend" | "append" | "shape"> & {
140
+ value?: string;
141
+ defaultValue?: string;
142
+ onChange?: (value: string) => void;
143
+ onComplete?: (value: string) => void;
144
+ /** Number of characters. Alias: `maxLength`. Defaults to 6. */
145
+ length?: number;
146
+ maxLength?: number;
147
+ type?: PinInputType;
148
+ /** Overrides `type`'s value filter. A `^...$` anchored source is expected. */
149
+ pattern?: RegExp;
150
+ /** Render each filled slot as a dot instead of the character. */
151
+ mask?: boolean;
152
+ /** Placeholder character shown in empty slots. */
153
+ placeholder?: string;
154
+ isReadOnly?: boolean;
155
+ autoFocus?: boolean;
156
+ name?: string;
157
+ /** Auto-render mode only: split slots into groups of this size. */
158
+ groupSize?: number;
159
+ /** Auto-render mode only: node rendered between groups. */
160
+ separator?: React$1.ReactNode;
161
+ children?: React$1.ReactNode;
162
+ };
163
+ declare function PinInput({ value, defaultValue, onChange, onComplete, length, maxLength, type, pattern, mask, placeholder, isReadOnly, autoFocus, name, groupSize, separator, children, inputRef: inputRefProp, classNames, styles, ...fieldProps }: PinInputProps): React$1.JSX.Element;
164
+ interface PinInputGroupProps extends React$1.HTMLAttributes<HTMLDivElement> {
165
+ _SILENCE_TS?: boolean;
166
+ }
167
+ declare function PinInputGroup({ className, ...props }: PinInputGroupProps): React$1.JSX.Element;
168
+ interface PinInputSlotProps extends Omit<React$1.HTMLAttributes<HTMLDivElement>, "children"> {
169
+ index: number;
170
+ }
171
+ declare function PinInputSlot({ index, className, ...props }: PinInputSlotProps): React$1.JSX.Element;
172
+ interface PinInputSeparatorProps extends React$1.HTMLAttributes<HTMLDivElement> {
173
+ _SILENCE_TS?: boolean;
174
+ }
175
+ declare function PinInputSeparator({ className, children, ...props }: PinInputSeparatorProps): React$1.JSX.Element;
176
+
138
177
  type TextWeight = "light" | "regular" | "medium" | "semi-bold" | "bold" | "heavy" | "inherit";
139
178
  type TextColorVariant = "light" | "lighter" | "dark" | "default";
140
179
  interface TextProps extends Omit<React$1.ComponentPropsWithRef<"span">, "color"> {
@@ -929,4 +968,4 @@ declare function pattern<T>(regex: RegExp, message?: string): FieldValidator<T>;
929
968
  declare function matches<T>(fieldName: keyof T & string, message?: string): FieldValidator<T>;
930
969
  declare function compose<T>(...fns: Array<FieldValidator<T>>): FieldValidator<T>;
931
970
 
932
- export { Avatar, AvatarGroup, type BaseModalProps, Button, ButtonGroup, Calendar, Checkbox, CheckboxGroup, CheckboxItem, ColorArea, ColorField, ColorPicker, ColorSlider, ColorSwatchPicker, ComboBox, type CustomToastRender, DateField, DatePicker, DateRangePicker, type FieldValidator, FileUploader, HoverCard, type HoverCardProps, IconButton, Input, ListBox, ListBoxItem, ListBoxSection, Loader, Menu, MenuContent, MenuItem, MenuSection, MenuTrigger, Modal, type ModalControls, type ModalDef, type ModalInputProps, type ModalKey, type ModalProps, ModalProvider, type ModalProviderProps, type ModalRegistry, type ModalResult, NumberInput, ListBoxItem as Option, type ParrotModalRegistry, Popover, PopoverContent, PopoverTrigger, Progress, Radio, RadioCard, RadioGroup, RadioItem, RangeCalendar, ListBoxSection as Section, Select, Separator, Slider, Space, Sticker, Switch, Tab, Table, Tabs, Tag, TagGroup, TagGroupItem, TagInput, Text, Textarea, ThemeProvider, TimeField, Timeline, type ToastAction, type ToastOptions, type ToastPosition, ToastRegion, type ToastRegionProps, type ToastVariant, Toggle, ToggleButton, ToggleGroup, Tooltip, type TooltipProps, type UseFormOptions, type UseFormReturn, compose, email, matches, max, maxLength, min, minLength, parseColor, pattern, required, toast, useForm, useModal, useModals, useTheme };
971
+ export { Avatar, AvatarGroup, type BaseModalProps, Button, ButtonGroup, Calendar, Checkbox, CheckboxGroup, CheckboxItem, ColorArea, ColorField, ColorPicker, ColorSlider, ColorSwatchPicker, ComboBox, type CustomToastRender, DateField, DatePicker, DateRangePicker, type FieldValidator, FileUploader, HoverCard, type HoverCardProps, IconButton, Input, ListBox, ListBoxItem, ListBoxSection, Loader, Menu, MenuContent, MenuItem, MenuSection, MenuTrigger, Modal, type ModalControls, type ModalDef, type ModalInputProps, type ModalKey, type ModalProps, ModalProvider, type ModalProviderProps, type ModalRegistry, type ModalResult, NumberInput, ListBoxItem as Option, type ParrotModalRegistry, PinInput, PinInputGroup, type PinInputGroupProps, type PinInputProps, PinInputSeparator, type PinInputSeparatorProps, PinInputSlot, type PinInputSlotProps, type PinInputType, Popover, PopoverContent, PopoverTrigger, Progress, Radio, RadioCard, RadioGroup, RadioItem, RangeCalendar, ListBoxSection as Section, Select, Separator, Slider, Space, Sticker, Switch, Tab, Table, Tabs, Tag, TagGroup, TagGroupItem, TagInput, Text, Textarea, ThemeProvider, TimeField, Timeline, type ToastAction, type ToastOptions, type ToastPosition, ToastRegion, type ToastRegionProps, type ToastVariant, Toggle, ToggleButton, ToggleGroup, Tooltip, type TooltipProps, type UseFormOptions, type UseFormReturn, compose, email, matches, max, maxLength, min, minLength, parseColor, pattern, required, toast, useForm, useModal, useModals, useTheme };
package/dist/index.d.ts CHANGED
@@ -135,6 +135,45 @@ type NumberInputProps = Omit<NumberFieldProps, "className" | "style" | "children
135
135
  };
136
136
  declare function NumberInput({ appearance, size, color, classNames, styles, append, prepend, placeholder, showSteppers, error, label, description, incrementIcon, decrementIcon, inputRef, wrapperRef, validationStatus, shape, radius, ...props }: NumberInputProps): React$1.JSX.Element;
137
137
 
138
+ type PinInputType = "numeric" | "alphanumeric" | "all";
139
+ type PinInputProps = Omit<FieldComponentProps<"input" | "control" | "group" | "slot">, "prepend" | "append" | "shape"> & {
140
+ value?: string;
141
+ defaultValue?: string;
142
+ onChange?: (value: string) => void;
143
+ onComplete?: (value: string) => void;
144
+ /** Number of characters. Alias: `maxLength`. Defaults to 6. */
145
+ length?: number;
146
+ maxLength?: number;
147
+ type?: PinInputType;
148
+ /** Overrides `type`'s value filter. A `^...$` anchored source is expected. */
149
+ pattern?: RegExp;
150
+ /** Render each filled slot as a dot instead of the character. */
151
+ mask?: boolean;
152
+ /** Placeholder character shown in empty slots. */
153
+ placeholder?: string;
154
+ isReadOnly?: boolean;
155
+ autoFocus?: boolean;
156
+ name?: string;
157
+ /** Auto-render mode only: split slots into groups of this size. */
158
+ groupSize?: number;
159
+ /** Auto-render mode only: node rendered between groups. */
160
+ separator?: React$1.ReactNode;
161
+ children?: React$1.ReactNode;
162
+ };
163
+ declare function PinInput({ value, defaultValue, onChange, onComplete, length, maxLength, type, pattern, mask, placeholder, isReadOnly, autoFocus, name, groupSize, separator, children, inputRef: inputRefProp, classNames, styles, ...fieldProps }: PinInputProps): React$1.JSX.Element;
164
+ interface PinInputGroupProps extends React$1.HTMLAttributes<HTMLDivElement> {
165
+ _SILENCE_TS?: boolean;
166
+ }
167
+ declare function PinInputGroup({ className, ...props }: PinInputGroupProps): React$1.JSX.Element;
168
+ interface PinInputSlotProps extends Omit<React$1.HTMLAttributes<HTMLDivElement>, "children"> {
169
+ index: number;
170
+ }
171
+ declare function PinInputSlot({ index, className, ...props }: PinInputSlotProps): React$1.JSX.Element;
172
+ interface PinInputSeparatorProps extends React$1.HTMLAttributes<HTMLDivElement> {
173
+ _SILENCE_TS?: boolean;
174
+ }
175
+ declare function PinInputSeparator({ className, children, ...props }: PinInputSeparatorProps): React$1.JSX.Element;
176
+
138
177
  type TextWeight = "light" | "regular" | "medium" | "semi-bold" | "bold" | "heavy" | "inherit";
139
178
  type TextColorVariant = "light" | "lighter" | "dark" | "default";
140
179
  interface TextProps extends Omit<React$1.ComponentPropsWithRef<"span">, "color"> {
@@ -929,4 +968,4 @@ declare function pattern<T>(regex: RegExp, message?: string): FieldValidator<T>;
929
968
  declare function matches<T>(fieldName: keyof T & string, message?: string): FieldValidator<T>;
930
969
  declare function compose<T>(...fns: Array<FieldValidator<T>>): FieldValidator<T>;
931
970
 
932
- export { Avatar, AvatarGroup, type BaseModalProps, Button, ButtonGroup, Calendar, Checkbox, CheckboxGroup, CheckboxItem, ColorArea, ColorField, ColorPicker, ColorSlider, ColorSwatchPicker, ComboBox, type CustomToastRender, DateField, DatePicker, DateRangePicker, type FieldValidator, FileUploader, HoverCard, type HoverCardProps, IconButton, Input, ListBox, ListBoxItem, ListBoxSection, Loader, Menu, MenuContent, MenuItem, MenuSection, MenuTrigger, Modal, type ModalControls, type ModalDef, type ModalInputProps, type ModalKey, type ModalProps, ModalProvider, type ModalProviderProps, type ModalRegistry, type ModalResult, NumberInput, ListBoxItem as Option, type ParrotModalRegistry, Popover, PopoverContent, PopoverTrigger, Progress, Radio, RadioCard, RadioGroup, RadioItem, RangeCalendar, ListBoxSection as Section, Select, Separator, Slider, Space, Sticker, Switch, Tab, Table, Tabs, Tag, TagGroup, TagGroupItem, TagInput, Text, Textarea, ThemeProvider, TimeField, Timeline, type ToastAction, type ToastOptions, type ToastPosition, ToastRegion, type ToastRegionProps, type ToastVariant, Toggle, ToggleButton, ToggleGroup, Tooltip, type TooltipProps, type UseFormOptions, type UseFormReturn, compose, email, matches, max, maxLength, min, minLength, parseColor, pattern, required, toast, useForm, useModal, useModals, useTheme };
971
+ export { Avatar, AvatarGroup, type BaseModalProps, Button, ButtonGroup, Calendar, Checkbox, CheckboxGroup, CheckboxItem, ColorArea, ColorField, ColorPicker, ColorSlider, ColorSwatchPicker, ComboBox, type CustomToastRender, DateField, DatePicker, DateRangePicker, type FieldValidator, FileUploader, HoverCard, type HoverCardProps, IconButton, Input, ListBox, ListBoxItem, ListBoxSection, Loader, Menu, MenuContent, MenuItem, MenuSection, MenuTrigger, Modal, type ModalControls, type ModalDef, type ModalInputProps, type ModalKey, type ModalProps, ModalProvider, type ModalProviderProps, type ModalRegistry, type ModalResult, NumberInput, ListBoxItem as Option, type ParrotModalRegistry, PinInput, PinInputGroup, type PinInputGroupProps, type PinInputProps, PinInputSeparator, type PinInputSeparatorProps, PinInputSlot, type PinInputSlotProps, type PinInputType, Popover, PopoverContent, PopoverTrigger, Progress, Radio, RadioCard, RadioGroup, RadioItem, RangeCalendar, ListBoxSection as Section, Select, Separator, Slider, Space, Sticker, Switch, Tab, Table, Tabs, Tag, TagGroup, TagGroupItem, TagInput, Text, Textarea, ThemeProvider, TimeField, Timeline, type ToastAction, type ToastOptions, type ToastPosition, ToastRegion, type ToastRegionProps, type ToastVariant, Toggle, ToggleButton, ToggleGroup, Tooltip, type TooltipProps, type UseFormOptions, type UseFormReturn, compose, email, matches, max, maxLength, min, minLength, parseColor, pattern, required, toast, useForm, useModal, useModals, useTheme };
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var React13 = require('react');
4
4
  var reactAriaComponents = require('react-aria-components');
5
+ var inputOtp = require('input-otp');
5
6
  var date = require('@internationalized/date');
6
7
  var reactStately = require('react-stately');
7
8
  var reactDom = require('react-dom');
@@ -962,6 +963,176 @@ function HiSelector({ size = "1em", ...props }) {
962
963
  function HiX({ size = "1em", ...props }) {
963
964
  return /* @__PURE__ */ React13__namespace.createElement("svg", { viewBox: "0 0 20 20", fill: "currentColor", "aria-hidden": "true", width: size, height: size, ...props }, /* @__PURE__ */ React13__namespace.createElement("path", { fillRule: "evenodd", d: "M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z", clipRule: "evenodd" }));
964
965
  }
966
+ var PATTERNS = {
967
+ numeric: inputOtp.REGEXP_ONLY_DIGITS,
968
+ alphanumeric: inputOtp.REGEXP_ONLY_DIGITS_AND_CHARS,
969
+ all: void 0
970
+ };
971
+ var INPUT_MODE = {
972
+ numeric: "numeric",
973
+ alphanumeric: "text",
974
+ all: "text"
975
+ };
976
+ var PinInputConfigContext = React13__namespace.createContext(null);
977
+ function usePinInputConfig() {
978
+ const ctx = React13__namespace.useContext(PinInputConfigContext);
979
+ if (!ctx) {
980
+ throw new Error(
981
+ "PinInput compound components must be rendered inside <PinInput>"
982
+ );
983
+ }
984
+ return ctx;
985
+ }
986
+ function PinInput({
987
+ value,
988
+ defaultValue,
989
+ onChange,
990
+ onComplete,
991
+ length,
992
+ maxLength: maxLength2,
993
+ type = "numeric",
994
+ pattern: pattern2,
995
+ mask = false,
996
+ placeholder,
997
+ isReadOnly = false,
998
+ autoFocus,
999
+ name,
1000
+ groupSize,
1001
+ separator,
1002
+ children,
1003
+ inputRef: inputRefProp,
1004
+ classNames,
1005
+ styles,
1006
+ ...fieldProps
1007
+ }) {
1008
+ const resolvedMax = maxLength2 ?? length ?? 6;
1009
+ const isDisabled = fieldProps.isDisabled ?? false;
1010
+ const isInvalid = !!fieldProps.error;
1011
+ const isControlled = value !== void 0;
1012
+ const [internalValue, setInternalValue] = React13__namespace.useState(defaultValue ?? "");
1013
+ const currentValue = isControlled ? value : internalValue;
1014
+ function handleChange(next) {
1015
+ if (!isControlled) setInternalValue(next);
1016
+ onChange?.(next);
1017
+ }
1018
+ const config = React13__namespace.useMemo(
1019
+ () => ({ mask, placeholder, isDisabled, isInvalid }),
1020
+ [mask, placeholder, isDisabled, isInvalid]
1021
+ );
1022
+ const fieldError = React13__namespace.useMemo(
1023
+ () => ({
1024
+ isInvalid,
1025
+ validationErrors: [],
1026
+ validationDetails: {}
1027
+ }),
1028
+ [isInvalid]
1029
+ );
1030
+ const content = children ?? renderSlots(resolvedMax, groupSize, separator, classNames?.slot);
1031
+ return /* @__PURE__ */ React13__namespace.createElement(PinInputConfigContext.Provider, { value: config }, /* @__PURE__ */ React13__namespace.createElement(reactAriaComponents.FieldErrorContext.Provider, { value: fieldError }, /* @__PURE__ */ React13__namespace.createElement(
1032
+ Field,
1033
+ {
1034
+ ...fieldProps,
1035
+ classNames,
1036
+ styles,
1037
+ replaceDefaultControlWrapper: true
1038
+ },
1039
+ /* @__PURE__ */ React13__namespace.createElement(
1040
+ "div",
1041
+ {
1042
+ className: cn("prt-pin", classNames?.control),
1043
+ style: styles?.control,
1044
+ "data-disabled": isDisabled || void 0,
1045
+ "data-invalid": isInvalid || void 0
1046
+ },
1047
+ /* @__PURE__ */ React13__namespace.createElement(
1048
+ inputOtp.OTPInput,
1049
+ {
1050
+ ref: inputRefProp,
1051
+ value: currentValue,
1052
+ onChange: handleChange,
1053
+ onComplete,
1054
+ maxLength: resolvedMax,
1055
+ pattern: pattern2?.source ?? PATTERNS[type],
1056
+ inputMode: INPUT_MODE[type],
1057
+ textAlign: "center",
1058
+ autoComplete: "one-time-code",
1059
+ autoCorrect: "off",
1060
+ autoCapitalize: "off",
1061
+ spellCheck: false,
1062
+ autoFocus,
1063
+ disabled: isDisabled,
1064
+ readOnly: isReadOnly,
1065
+ name,
1066
+ "aria-invalid": isInvalid || void 0,
1067
+ containerClassName: "prt-pin-otp",
1068
+ className: cn("prt-pin-input", classNames?.input),
1069
+ style: styles?.input
1070
+ },
1071
+ content
1072
+ )
1073
+ )
1074
+ )));
1075
+ }
1076
+ function renderSlots(maxLength2, groupSize, separator, slotClassName) {
1077
+ const size = groupSize && groupSize > 0 ? groupSize : maxLength2;
1078
+ const groups = [];
1079
+ for (let i = 0; i < maxLength2; i += size) {
1080
+ groups.push(
1081
+ Array.from({ length: Math.min(size, maxLength2 - i) }, (_, j) => i + j)
1082
+ );
1083
+ }
1084
+ return groups.map((indices, groupIndex) => /* @__PURE__ */ React13__namespace.createElement(React13__namespace.Fragment, { key: groupIndex }, groupIndex > 0 && /* @__PURE__ */ React13__namespace.createElement(PinInputSeparator, null, separator), /* @__PURE__ */ React13__namespace.createElement(PinInputGroup, null, indices.map((index) => /* @__PURE__ */ React13__namespace.createElement(PinInputSlot, { key: index, index, className: slotClassName })))));
1085
+ }
1086
+ function PinInputGroup({ className, ...props }) {
1087
+ return /* @__PURE__ */ React13__namespace.createElement(
1088
+ "div",
1089
+ {
1090
+ className: cn("prt-pin-group", className),
1091
+ "data-slot": "group",
1092
+ ...props
1093
+ }
1094
+ );
1095
+ }
1096
+ function PinInputSlot({
1097
+ index,
1098
+ className,
1099
+ ...props
1100
+ }) {
1101
+ const { mask, placeholder, isDisabled, isInvalid } = usePinInputConfig();
1102
+ const { slots } = React13__namespace.useContext(inputOtp.OTPInputContext);
1103
+ const slot = slots[index];
1104
+ const char = slot?.char ?? null;
1105
+ return /* @__PURE__ */ React13__namespace.createElement(
1106
+ "div",
1107
+ {
1108
+ ...props,
1109
+ className: cn("prt-pin-slot", className),
1110
+ "data-slot": "slot",
1111
+ "data-active": slot?.isActive || void 0,
1112
+ "data-filled": !!char || void 0,
1113
+ "data-disabled": isDisabled || void 0,
1114
+ "data-invalid": isInvalid || void 0
1115
+ },
1116
+ char !== null ? /* @__PURE__ */ React13__namespace.createElement("span", { className: "prt-pin-char" }, mask ? "\u2022" : char) : placeholder ? /* @__PURE__ */ React13__namespace.createElement("span", { className: "prt-pin-placeholder" }, placeholder) : null,
1117
+ slot?.hasFakeCaret && /* @__PURE__ */ React13__namespace.createElement("div", { className: "prt-pin-caret", "aria-hidden": true })
1118
+ );
1119
+ }
1120
+ function PinInputSeparator({
1121
+ className,
1122
+ children,
1123
+ ...props
1124
+ }) {
1125
+ return /* @__PURE__ */ React13__namespace.createElement(
1126
+ "div",
1127
+ {
1128
+ className: cn("prt-pin-separator", className),
1129
+ "data-slot": "separator",
1130
+ "aria-hidden": true,
1131
+ ...props
1132
+ },
1133
+ children ?? "-"
1134
+ );
1135
+ }
965
1136
 
966
1137
  // src/utils/theme.ts
967
1138
  var supportedColors = [
@@ -4675,6 +4846,10 @@ exports.Modal = Modal;
4675
4846
  exports.ModalProvider = ModalProvider;
4676
4847
  exports.NumberInput = NumberInput;
4677
4848
  exports.Option = ListBoxItem;
4849
+ exports.PinInput = PinInput;
4850
+ exports.PinInputGroup = PinInputGroup;
4851
+ exports.PinInputSeparator = PinInputSeparator;
4852
+ exports.PinInputSlot = PinInputSlot;
4678
4853
  exports.Popover = Popover;
4679
4854
  exports.PopoverContent = PopoverContent;
4680
4855
  exports.PopoverTrigger = PopoverTrigger;