@wello-dev/core 1.0.4 → 1.0.6

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.
Files changed (73) hide show
  1. package/dist/{chunk-FIAJMBSD.js → chunk-2TFJ4SMR.js} +3 -3
  2. package/dist/chunk-2TFJ4SMR.js.map +1 -0
  3. package/dist/{chunk-6U4Y3AUT.js → chunk-2WHZJI3S.js} +3 -3
  4. package/dist/{chunk-F2FJLMJF.js → chunk-652ZEQV7.js} +4 -4
  5. package/dist/{chunk-YQOS23WP.js → chunk-7EINGVGG.js} +2 -2
  6. package/dist/{chunk-YOL5PMHU.js → chunk-7S7RIVCI.js} +2 -2
  7. package/dist/{chunk-PPKKOBHB.js → chunk-A76QHCP5.js} +2 -2
  8. package/dist/{chunk-TJUOXXLK.js → chunk-BZPG4NZ6.js} +2 -2
  9. package/dist/chunk-DRSBB5T4.js +206 -0
  10. package/dist/chunk-DRSBB5T4.js.map +1 -0
  11. package/dist/{chunk-HGYIOR5F.js → chunk-ESMDK5GY.js} +2 -2
  12. package/dist/{chunk-GD5URO3H.js → chunk-FSR3OEUP.js} +4 -4
  13. package/dist/{chunk-52P4CIAK.js → chunk-HBBXBVK6.js} +2 -2
  14. package/dist/{chunk-63PSLIW5.js → chunk-K3B2RENY.js} +2 -2
  15. package/dist/{chunk-ZTOAB4HM.js → chunk-NGXT7GNE.js} +2 -2
  16. package/dist/{chunk-O4MQLZEH.js → chunk-NH26XE7T.js} +2 -2
  17. package/dist/{chunk-7GLDYLJ6.js → chunk-O6A7IBIW.js} +2 -2
  18. package/dist/{chunk-F4OMXH3E.js → chunk-QCMTAQSP.js} +17 -10
  19. package/dist/chunk-QCMTAQSP.js.map +1 -0
  20. package/dist/{chunk-2XGMU4QA.js → chunk-RVFCTNPD.js} +20 -4
  21. package/dist/chunk-RVFCTNPD.js.map +1 -0
  22. package/dist/{chunk-KEYIOWAG.js → chunk-TIVOXLDX.js} +3 -3
  23. package/dist/{chunk-KEYIOWAG.js.map → chunk-TIVOXLDX.js.map} +1 -1
  24. package/dist/{chunk-QZFPW75D.js → chunk-XBLREJCR.js} +30 -3
  25. package/dist/chunk-XBLREJCR.js.map +1 -0
  26. package/dist/{chunk-K2Q5Q6WQ.js → chunk-YRKCM3OL.js} +10 -6
  27. package/dist/chunk-YRKCM3OL.js.map +1 -0
  28. package/dist/components/ColorPicker/ColorInput.js +4 -4
  29. package/dist/components/Combobox/Combobox.js +4 -4
  30. package/dist/components/Combobox/Select.js +5 -5
  31. package/dist/components/Combobox/TagsInput.js +5 -5
  32. package/dist/components/Dialog/Dialog.js +2 -2
  33. package/dist/components/Dropzone/Dropzone.js +4 -4
  34. package/dist/components/Menu/Menu.js +4 -4
  35. package/dist/components/Modal/Drawer.js +3 -3
  36. package/dist/components/Modal/Modal.js +3 -3
  37. package/dist/components/Modal/ModalBase.js +2 -2
  38. package/dist/components/NumberFormatter/NumberFormatter.js +1 -1
  39. package/dist/components/PhoneInput/PhoneInput.js +6 -6
  40. package/dist/components/Popover/Popover.js +3 -3
  41. package/dist/components/Portal/Portal.js +1 -1
  42. package/dist/components/TextInput/TextInput.js +2 -2
  43. package/dist/components/Tooltip/Tooltip.js +3 -3
  44. package/dist/index.cjs +163 -95
  45. package/dist/index.cjs.map +1 -1
  46. package/dist/index.d.cts +7 -2
  47. package/dist/index.d.ts +7 -2
  48. package/dist/index.js +114 -114
  49. package/dist/shadcn/Command.js +6 -6
  50. package/dist/shadcn/Dialog.js +5 -5
  51. package/dist/shadcn/Floating.js +6 -6
  52. package/dist/styles.css +123 -15
  53. package/package.json +1 -1
  54. package/dist/chunk-2XGMU4QA.js.map +0 -1
  55. package/dist/chunk-F4OMXH3E.js.map +0 -1
  56. package/dist/chunk-FIAJMBSD.js.map +0 -1
  57. package/dist/chunk-K2Q5Q6WQ.js.map +0 -1
  58. package/dist/chunk-QZFPW75D.js.map +0 -1
  59. package/dist/chunk-YHPHWOAE.js +0 -192
  60. package/dist/chunk-YHPHWOAE.js.map +0 -1
  61. /package/dist/{chunk-6U4Y3AUT.js.map → chunk-2WHZJI3S.js.map} +0 -0
  62. /package/dist/{chunk-F2FJLMJF.js.map → chunk-652ZEQV7.js.map} +0 -0
  63. /package/dist/{chunk-YQOS23WP.js.map → chunk-7EINGVGG.js.map} +0 -0
  64. /package/dist/{chunk-YOL5PMHU.js.map → chunk-7S7RIVCI.js.map} +0 -0
  65. /package/dist/{chunk-PPKKOBHB.js.map → chunk-A76QHCP5.js.map} +0 -0
  66. /package/dist/{chunk-TJUOXXLK.js.map → chunk-BZPG4NZ6.js.map} +0 -0
  67. /package/dist/{chunk-HGYIOR5F.js.map → chunk-ESMDK5GY.js.map} +0 -0
  68. /package/dist/{chunk-GD5URO3H.js.map → chunk-FSR3OEUP.js.map} +0 -0
  69. /package/dist/{chunk-52P4CIAK.js.map → chunk-HBBXBVK6.js.map} +0 -0
  70. /package/dist/{chunk-63PSLIW5.js.map → chunk-K3B2RENY.js.map} +0 -0
  71. /package/dist/{chunk-ZTOAB4HM.js.map → chunk-NGXT7GNE.js.map} +0 -0
  72. /package/dist/{chunk-O4MQLZEH.js.map → chunk-NH26XE7T.js.map} +0 -0
  73. /package/dist/{chunk-7GLDYLJ6.js.map → chunk-O6A7IBIW.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/PhoneInput/PhoneInput.tsx","../src/components/PhoneInput/countries.ts"],"sourcesContent":["import { useEndpointLoaders } from \"../../core/api/api\";\r\nimport { useWelloLabels } from \"../../core/provider/labels\";\r\nimport { useEffect, useMemo, useRef, useState, type ReactNode } from \"react\";\r\nimport { Box, type BoxProps } from \"../../core/Box/Box\";\r\nimport { factory } from \"../../core/factory/factory\";\r\nimport { useComponentStyles, useProps, type StylesApiProps } from \"../../core/styles-api/styles-api\";\r\nimport { useId } from \"../../core/utils\";\r\nimport { Select, type LoadOptionsInput, type SingleSelectProps } from \"../Combobox/Select\";\r\nimport { InputError, InputWrapper } from \"../Input/Input\";\r\nimport { Skeleton } from \"../Skeleton/Skeleton\";\r\nimport { ALL_PHONE_COUNTRIES, DEFAULT_PHONE_CODE } from \"./countries\";\r\n\r\nexport type PhoneInputStylesNames = \"root\" | \"label\" | \"description\" | \"field\" | \"code\" | \"codeValue\" | \"flag\" | \"dialCode\" | \"input\" | \"errors\" | \"error\";\r\n\r\n/** A country. Your API's names work too: `phone_code`, `phone_limit`, `phone_number_limit`, `phone_starting_number`. */\r\nexport interface PhoneCountry {\r\n /** Dial code, without + */\r\n code?: string | number;\r\n phone_code?: string | number;\r\n value?: string | number;\r\n name?: string;\r\n /** Image URL or your own element */\r\n flag?: ReactNode;\r\n /** Digits allowed */\r\n limit?: number | string | null;\r\n phone_limit?: number | string | null;\r\n phone_number_limit?: number | string | null;\r\n /** First digit of the number; applied when the country changes */\r\n startingNumber?: number | string | null;\r\n phone_starting_number?: number | string | null;\r\n [key: string]: unknown;\r\n}\r\n\r\n/** A country with its fields resolved. */\r\nexport interface ResolvedPhoneCountry {\r\n code: string;\r\n name?: string;\r\n flag?: ReactNode;\r\n limit: number | null;\r\n startingNumber: string | null;\r\n /** What you passed */\r\n country: PhoneCountry;\r\n}\r\n\r\nexport interface PhoneInputProps extends BoxProps, StylesApiProps<PhoneInputStylesNames, PhoneInputProps> {\r\n label?: ReactNode;\r\n description?: ReactNode;\r\n /** Number error, under the field */\r\n error?: ReactNode;\r\n /** Dial code error, under the field */\r\n codeError?: ReactNode;\r\n required?: boolean;\r\n withAsterisk?: boolean;\r\n\r\n /** The number: digits only */\r\n value?: string | number | null;\r\n defaultValue?: string | number;\r\n onChange?: (value: string) => void;\r\n onBlur?: React.FocusEventHandler<HTMLInputElement>;\r\n name?: string;\r\n id?: string;\r\n /** Text, or a function of the limit. Default: \"10 digits\" */\r\n placeholder?: string | ((limit: number | null) => string);\r\n disabled?: boolean;\r\n readOnly?: boolean;\r\n /** Skeleton instead of the field */\r\n loading?: boolean;\r\n\r\n /** The dial code */\r\n code?: string | number | null;\r\n defaultCode?: string | number;\r\n /** `seed` is true when a fixed list picked its first country by itself, so a form shouldn't turn dirty */\r\n onCodeChange?: (code: string, country: ResolvedPhoneCountry | null, meta: { seed: boolean }) => void;\r\n /** Form name of the dial code (hidden input) */\r\n codeName?: string;\r\n /** Form name of the limit (hidden input) */\r\n limitName?: string;\r\n /** Form name of the country's required first digit(s) (hidden input) */\r\n startingNumberName?: string;\r\n\r\n /** Fixed list. Default: every country's dial code, starting on Egypt (+20) */\r\n countries?: PhoneCountry[];\r\n /**\r\n * Address of the countries on your API (`\"countries\"`): the only thing needed to fetch them. The base address and\r\n * headers come from the theme's `api`. With `params={{ paginate: false }}` everything is asked at once.\r\n */\r\n endpoint?: string | null;\r\n /** With `endpoint`: more query parameters */\r\n params?: Record<string, unknown>;\r\n /** With `endpoint`: use `api.generalBaseURL` */\r\n general?: boolean;\r\n /** With `endpoint`: turn the whole answer into the list of countries, when `{ data: [...] }` or an array doesn't fit */\r\n select?: (data: any) => PhoneCountry[];\r\n /** Fetch countries instead. Same input as Select's `loadOptions` */\r\n loadCountries?: (input: LoadOptionsInput) => Promise<PhoneCountry[] | { items: PhoneCountry[]; total?: number; hasMore?: boolean }> | PhoneCountry[] | { items: PhoneCountry[]; total?: number; hasMore?: boolean };\r\n /** Change it to fetch again */\r\n loadKey?: string | number | null;\r\n\r\n /** Digits allowed. Default: from the country */\r\n limit?: number | null;\r\n onLimitChange?: (limit: number | null) => void;\r\n onStartingNumberChange?: (startingNumber: string | null) => void;\r\n /** Change it to fire `onLimitChange` and `onStartingNumberChange` again (e.g. after a form reset) */\r\n resyncToken?: string | number | null;\r\n\r\n /** Own flag + code, in the field and the list */\r\n renderCountry?: (country: ResolvedPhoneCountry) => ReactNode;\r\n /** Shown when there is no dial code. Default: 'Code' */\r\n codePlaceholder?: string;\r\n /** Anything else for the dial code Select: search text, messages, classNames… */\r\n selectProps?: Partial<SingleSelectProps>;\r\n}\r\n\r\nconst DEFAULT_COUNTRIES = ALL_PHONE_COUNTRIES;\r\n\r\nconst digitsOnly = (value: unknown) => String(value ?? \"\").replace(/\\D/g, \"\");\r\n\r\nfunction parseLimit(value: unknown) {\r\n const limit = Number(value);\r\n return Number.isFinite(limit) && limit > 0 ? limit : null;\r\n}\r\n\r\n/** Country `startingNumber` / `phone_starting_number` as digits. */\r\nexport function normalizeStartingNumber(value: unknown): string | null {\r\n if (value == null || value === \"\") return null;\r\n const digits = digitsOnly(value);\r\n return digits || null;\r\n}\r\n\r\n/**\r\n * True when digits already match the required start, or are still a partial prefix of it\r\n * (so typing the first digit of a multi-digit start is allowed).\r\n */\r\nexport function matchesPhoneStartingNumber(digits: string, start: string | null): boolean {\r\n if (!start || !digits) return true;\r\n return digits.startsWith(start) || start.startsWith(digits);\r\n}\r\n\r\n/** Fills in a country's fields from any of their names. */\r\nexport function resolvePhoneCountry(country: PhoneCountry): ResolvedPhoneCountry {\r\n return {\r\n code: String(country.code ?? country.phone_code ?? country.value ?? \"\"),\r\n name: country.name,\r\n flag: country.flag,\r\n limit: parseLimit(country.limit ?? country.phone_limit ?? country.phone_number_limit),\r\n startingNumber: normalizeStartingNumber(country.startingNumber ?? country.phone_starting_number),\r\n country,\r\n };\r\n}\r\n\r\n/** Number after moving to a country: right first digit, not over its limit. */\r\nexport function fitPhoneNumber(value: unknown, country: Pick<ResolvedPhoneCountry, \"limit\" | \"startingNumber\">) {\r\n let phone = digitsOnly(value);\r\n if (phone && country.startingNumber && !phone.startsWith(country.startingNumber)) {\r\n phone = country.startingNumber + phone.slice(country.startingNumber.length);\r\n }\r\n return country.limit ? phone.slice(0, country.limit) : phone;\r\n}\r\n\r\n/**\r\n * Phone number with a dial code. Keeps digits only, limits them per country and fixes the\r\n * first digit when the country changes. Takes react-hook-form's `{...field}` for the number.\r\n *\r\n * @example\r\n * <PhoneInput label=\"Phone\" value={phone} onChange={setPhone} code={code} onCodeChange={setCode} countries={[\r\n * { code: \"966\", name: \"Saudi Arabia\", flag: \"https://flagcdn.com/sa.svg\", limit: 9, startingNumber: 5 },\r\n * { code: \"20\", name: \"Egypt\", flag: \"https://flagcdn.com/eg.svg\", limit: 10, startingNumber: 1 },\r\n * ]} />\r\n * <PhoneInput {...field} loadCountries={() => api.countries().then((r) => r.data)} onCodeChange={(c) => setValue(\"phone_code\", c)} onLimitChange={(l) => setValue(\"phone_limit\", l)} />\r\n */\r\nexport const PhoneInput = factory<{ props: PhoneInputProps; ref: HTMLInputElement; stylesNames: PhoneInputStylesNames }>((_props, ref) => {\r\n const labels = useWelloLabels();\r\n const props = useProps(\"PhoneInput\", {}, _props);\r\n const [getStyles, rest] = useComponentStyles(\"PhoneInput\", props);\r\n const {\r\n label,\r\n description,\r\n error,\r\n codeError,\r\n required,\r\n withAsterisk,\r\n value: controlled,\r\n defaultValue,\r\n onChange,\r\n onBlur,\r\n name,\r\n id,\r\n placeholder,\r\n disabled,\r\n readOnly,\r\n loading,\r\n code: codeProp,\r\n defaultCode,\r\n onCodeChange,\r\n codeName,\r\n limitName,\r\n startingNumberName,\r\n countries,\r\n endpoint,\r\n params,\r\n general,\r\n select: selectCountries,\r\n loadCountries: loadCountriesProp,\r\n loadKey: loadKeyProp,\r\n limit: limitProp,\r\n onLimitChange,\r\n onStartingNumberChange,\r\n resyncToken,\r\n renderCountry,\r\n codePlaceholder = labels.phoneCode,\r\n selectProps,\r\n // Layout goes on the root.\r\n m, mt, mb, ml, mr, ms, me, mx, my, w, miw, maw, flex,\r\n ...inputProps\r\n } = rest;\r\n const inputId = useId(id);\r\n const fromEndpoint = useEndpointLoaders({ endpoint, params, general, select: selectCountries, hasShow: false });\r\n const loadCountries = (loadCountriesProp ?? fromEndpoint.loadOptions) as PhoneInputProps[\"loadCountries\"];\r\n const loadKey = loadKeyProp ?? fromEndpoint.loadKey;\r\n const remote = !!loadCountries;\r\n\r\n // Number\r\n const [internal, setInternal] = useState(digitsOnly(defaultValue));\r\n const phone = controlled !== undefined ? digitsOnly(controlled) : internal;\r\n const setPhone = (next: string) => {\r\n if (controlled === undefined) setInternal(next);\r\n onChange?.(next);\r\n };\r\n\r\n // Dial code\r\n const [codeInternal, setCodeInternal] = useState(defaultCode === undefined ? \"\" : String(defaultCode));\r\n const code = codeProp !== undefined ? String(codeProp ?? \"\") : codeInternal;\r\n const list = useMemo(() => (countries?.length ? countries : DEFAULT_COUNTRIES).map(resolvePhoneCountry), [countries]);\r\n const [fetched, setFetched] = useState<ResolvedPhoneCountry | null>(null);\r\n const country = remote ? (fetched && fetched.code === code ? fetched : null) : (list.find((item) => item.code === code) ?? null);\r\n const limit = limitProp ?? country?.limit ?? null;\r\n const startingNumber = country?.startingNumber ?? null;\r\n\r\n const setCode = (next: string, resolved: ResolvedPhoneCountry | null, seed = false) => {\r\n if (codeProp === undefined) setCodeInternal(next);\r\n onCodeChange?.(next, resolved, { seed });\r\n };\r\n\r\n // A fixed list always has a code: start on the first country.\r\n // With no list of your own, the full list starts on Egypt, not on the first name alphabetically.\r\n const usesDefaults = !remote && !countries?.length;\r\n const first = remote ? undefined : usesDefaults ? (list.find((item) => item.code === DEFAULT_PHONE_CODE) ?? list[0]) : list[0];\r\n useEffect(() => {\r\n if (!code && first) setCode(first.code, first, true);\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, [code, first?.code]);\r\n\r\n // Tell the form the limit and first digit of the current country.\r\n const callbacks = useRef({ onLimitChange, onStartingNumberChange });\r\n callbacks.current = { onLimitChange, onStartingNumberChange };\r\n const countryLimit = country?.limit ?? null;\r\n useEffect(() => callbacks.current.onLimitChange?.(countryLimit), [countryLimit, resyncToken]);\r\n useEffect(() => callbacks.current.onStartingNumberChange?.(startingNumber), [startingNumber, resyncToken]);\r\n\r\n // Changing country fits the number to it. The first country is left alone: that's saved data.\r\n const lastCode = useRef(\"\");\r\n const latest = useRef({ phone, setPhone });\r\n latest.current = { phone, setPhone };\r\n const countryCode = country?.code ?? \"\";\r\n useEffect(() => {\r\n const previous = lastCode.current;\r\n lastCode.current = countryCode;\r\n if (!previous || !country || previous === countryCode) return;\r\n const fitted = fitPhoneNumber(latest.current.phone, country);\r\n if (fitted !== latest.current.phone) latest.current.setPhone(fitted);\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, [countryCode]);\r\n\r\n const showCountry = (item: ResolvedPhoneCountry) =>\r\n renderCountry ? (\r\n renderCountry(item)\r\n ) : (\r\n // Always LTR: flag then dial code (RTL pages were flipping to \"966 | flag\").\r\n <span {...getStyles(\"codeValue\")} dir=\"ltr\">\r\n {typeof item.flag === \"string\" ? <img {...getStyles(\"flag\")} src={item.flag} alt={item.name ?? \"\"} onError={(event) => (event.currentTarget.style.display = \"none\")} /> : item.flag}\r\n <span {...getStyles(\"dialCode\")}>{item.code}</span>\r\n </span>\r\n );\r\n const toOption = (item: ResolvedPhoneCountry) => ({ value: item.code, label: showCountry(item), searchText: `${item.name ?? \"\"} ${item.code}`, resolved: item });\r\n\r\n const hasMessage = (message: ReactNode) => message !== undefined && message !== null && message !== false && message !== true && message !== \"\";\r\n const startingMismatch =\r\n !!startingNumber && !!phone && !matchesPhoneStartingNumber(phone, startingNumber);\r\n const startingError = startingMismatch ? labels.phoneStartingNumber(startingNumber) : null;\r\n // External `error` wins; otherwise show the starting-digit message while typing.\r\n const numberError = hasMessage(error) ? error : startingError;\r\n const hasError = hasMessage(numberError) || hasMessage(codeError);\r\n const errorId = `${inputId}-phone-error`;\r\n const shownPlaceholder = typeof placeholder === \"function\" ? placeholder(limit) : (placeholder ?? (limit ? labels.phoneDigits(limit) : undefined));\r\n const layout = { m, mt, mb, ml, mr, ms, me, mx, my, w, miw, maw, flex };\r\n\r\n if (loading) return <Skeleton height={36} radius={999} {...layout} />;\r\n\r\n const select = {\r\n value: code,\r\n emptyValue: \"\",\r\n disabled,\r\n readOnly,\r\n placeholder: codePlaceholder,\r\n withFooter: false,\r\n radius: 0,\r\n comboboxProps: { width: 240, position: \"bottom-start\" as const, withinPortal: true },\r\n \"aria-invalid\": !!codeError || undefined,\r\n \"aria-label\": codePlaceholder,\r\n ...selectProps,\r\n onChange: (next: unknown, option: unknown) => {\r\n const resolved = (option as { resolved?: ResolvedPhoneCountry } | null)?.resolved ?? null;\r\n if (resolved) setFetched(resolved);\r\n setCode(String(next ?? \"\"), resolved);\r\n selectProps?.onChange?.(next, option as never);\r\n },\r\n };\r\n\r\n return (\r\n <InputWrapper\r\n id={inputId}\r\n label={label}\r\n description={description}\r\n required={required || withAsterisk}\r\n labelProps={getStyles(\"label\")}\r\n descriptionProps={getStyles(\"description\")}\r\n {...getStyles(\"root\")}\r\n {...layout}\r\n >\r\n {/* The code stays on the left in both directions, like a written phone number. */}\r\n <Box {...getStyles(\"field\")} mod={{ error: hasError, disabled }}>\r\n <div {...getStyles(\"code\")} data-error={codeError ? true : undefined}>\r\n {remote ? (\r\n <Select\r\n {...select}\r\n allowDeselect\r\n onOptionSelect={(option) => {\r\n setFetched((option as { resolved: ResolvedPhoneCountry }).resolved);\r\n selectProps?.onOptionSelect?.(option);\r\n }}\r\n loadKey={loadKey}\r\n loadOptions={(input) =>\r\n Promise.resolve(loadCountries!(input)).then((result) =>\r\n Array.isArray(result) ? result.map((item) => toOption(resolvePhoneCountry(item))) : { ...result, items: result.items.map((item) => toOption(resolvePhoneCountry(item))) },\r\n )\r\n }\r\n />\r\n ) : list.length > 1 ? (\r\n <Select {...select} allowDeselect={false} options={list.map(toOption)} />\r\n ) : (\r\n <span className=\"wello-PhoneInput-single\">{list[0] && showCountry(list[0])}</span>\r\n )}\r\n </div>\r\n <input\r\n {...(inputProps as object)}\r\n {...getStyles(\"input\")}\r\n ref={ref}\r\n id={inputId}\r\n type=\"tel\"\r\n inputMode=\"numeric\"\r\n autoComplete=\"tel-national\"\r\n // Digits + placeholders stay LTR (avoids \"أرقام 9\" bidi flip on RTL pages).\r\n dir=\"ltr\"\r\n name={name}\r\n value={phone}\r\n disabled={disabled}\r\n readOnly={readOnly}\r\n required={required}\r\n maxLength={limit ?? undefined}\r\n placeholder={shownPlaceholder}\r\n aria-invalid={hasMessage(numberError) || undefined}\r\n aria-describedby={hasMessage(numberError) ? errorId : undefined}\r\n onBlur={onBlur}\r\n onChange={(event) => {\r\n const digits = digitsOnly(event.currentTarget.value);\r\n setPhone(limit ? digits.slice(0, limit) : digits);\r\n }}\r\n />\r\n </Box>\r\n {(hasMessage(numberError) || hasMessage(codeError)) && (\r\n <div {...getStyles(\"errors\")}>\r\n {hasMessage(numberError) && (\r\n <InputError {...getStyles(\"error\")} id={errorId}>\r\n {numberError}\r\n </InputError>\r\n )}\r\n {hasMessage(codeError) && <InputError {...getStyles(\"error\")} data-code>{codeError}</InputError>}\r\n </div>\r\n )}\r\n {codeName && <input type=\"hidden\" name={codeName} value={code} />}\r\n {limitName && <input type=\"hidden\" name={limitName} value={limit ?? \"\"} />}\r\n {startingNumberName && <input type=\"hidden\" name={startingNumberName} value={startingNumber ?? \"\"} />}\r\n </InputWrapper>\r\n );\r\n});\r\nPhoneInput.displayName = \"PhoneInput\";\r\n","import type { PhoneCountry } from \"./PhoneInput\";\n\n/**\n * [ISO code, name, dial code]. One entry for each dial code: where countries share one (+1, +7, +44) the main\n * country stands for it, and the name says so. Digit limits differ by number type, so only Egypt (the default)\n * has one; pass your own `countries` for the rest.\n */\nconst ROWS: [string, string, string][] = [\n [\"af\", \"Afghanistan\", \"93\"],\n [\"al\", \"Albania\", \"355\"],\n [\"dz\", \"Algeria\", \"213\"],\n [\"ad\", \"Andorra\", \"376\"],\n [\"ao\", \"Angola\", \"244\"],\n [\"ar\", \"Argentina\", \"54\"],\n [\"am\", \"Armenia\", \"374\"],\n [\"aw\", \"Aruba\", \"297\"],\n [\"au\", \"Australia\", \"61\"],\n [\"at\", \"Austria\", \"43\"],\n [\"az\", \"Azerbaijan\", \"994\"],\n [\"bh\", \"Bahrain\", \"973\"],\n [\"bd\", \"Bangladesh\", \"880\"],\n [\"by\", \"Belarus\", \"375\"],\n [\"be\", \"Belgium\", \"32\"],\n [\"bz\", \"Belize\", \"501\"],\n [\"bj\", \"Benin\", \"229\"],\n [\"bt\", \"Bhutan\", \"975\"],\n [\"bo\", \"Bolivia\", \"591\"],\n [\"ba\", \"Bosnia and Herzegovina\", \"387\"],\n [\"bw\", \"Botswana\", \"267\"],\n [\"br\", \"Brazil\", \"55\"],\n [\"bn\", \"Brunei\", \"673\"],\n [\"bg\", \"Bulgaria\", \"359\"],\n [\"bf\", \"Burkina Faso\", \"226\"],\n [\"bi\", \"Burundi\", \"257\"],\n [\"kh\", \"Cambodia\", \"855\"],\n [\"cm\", \"Cameroon\", \"237\"],\n [\"cv\", \"Cape Verde\", \"238\"],\n [\"cf\", \"Central African Republic\", \"236\"],\n [\"td\", \"Chad\", \"235\"],\n [\"cl\", \"Chile\", \"56\"],\n [\"cn\", \"China\", \"86\"],\n [\"co\", \"Colombia\", \"57\"],\n [\"km\", \"Comoros\", \"269\"],\n [\"cg\", \"Congo\", \"242\"],\n [\"cd\", \"DR Congo\", \"243\"],\n [\"cr\", \"Costa Rica\", \"506\"],\n [\"ci\", \"Côte d'Ivoire\", \"225\"],\n [\"hr\", \"Croatia\", \"385\"],\n [\"cu\", \"Cuba\", \"53\"],\n [\"cy\", \"Cyprus\", \"357\"],\n [\"cz\", \"Czechia\", \"420\"],\n [\"dk\", \"Denmark\", \"45\"],\n [\"dj\", \"Djibouti\", \"253\"],\n [\"ec\", \"Ecuador\", \"593\"],\n [\"eg\", \"Egypt\", \"20\"],\n [\"sv\", \"El Salvador\", \"503\"],\n [\"gq\", \"Equatorial Guinea\", \"240\"],\n [\"er\", \"Eritrea\", \"291\"],\n [\"ee\", \"Estonia\", \"372\"],\n [\"sz\", \"Eswatini\", \"268\"],\n [\"et\", \"Ethiopia\", \"251\"],\n [\"fj\", \"Fiji\", \"679\"],\n [\"fi\", \"Finland\", \"358\"],\n [\"fr\", \"France\", \"33\"],\n [\"gf\", \"French Guiana\", \"594\"],\n [\"pf\", \"French Polynesia\", \"689\"],\n [\"ga\", \"Gabon\", \"241\"],\n [\"gm\", \"Gambia\", \"220\"],\n [\"ge\", \"Georgia\", \"995\"],\n [\"de\", \"Germany\", \"49\"],\n [\"gh\", \"Ghana\", \"233\"],\n [\"gi\", \"Gibraltar\", \"350\"],\n [\"gr\", \"Greece\", \"30\"],\n [\"gl\", \"Greenland\", \"299\"],\n [\"gp\", \"Guadeloupe\", \"590\"],\n [\"gt\", \"Guatemala\", \"502\"],\n [\"gn\", \"Guinea\", \"224\"],\n [\"gw\", \"Guinea-Bissau\", \"245\"],\n [\"gy\", \"Guyana\", \"592\"],\n [\"ht\", \"Haiti\", \"509\"],\n [\"hn\", \"Honduras\", \"504\"],\n [\"hk\", \"Hong Kong\", \"852\"],\n [\"hu\", \"Hungary\", \"36\"],\n [\"is\", \"Iceland\", \"354\"],\n [\"in\", \"India\", \"91\"],\n [\"id\", \"Indonesia\", \"62\"],\n [\"ir\", \"Iran\", \"98\"],\n [\"iq\", \"Iraq\", \"964\"],\n [\"ie\", \"Ireland\", \"353\"],\n // [\"il\", \"Israel\", \"972\"],\n [\"it\", \"Italy\", \"39\"],\n [\"jp\", \"Japan\", \"81\"],\n [\"jo\", \"Jordan\", \"962\"],\n [\"ke\", \"Kenya\", \"254\"],\n [\"ki\", \"Kiribati\", \"686\"],\n [\"kw\", \"Kuwait\", \"965\"],\n [\"kg\", \"Kyrgyzstan\", \"996\"],\n [\"la\", \"Laos\", \"856\"],\n [\"lv\", \"Latvia\", \"371\"],\n [\"lb\", \"Lebanon\", \"961\"],\n [\"ls\", \"Lesotho\", \"266\"],\n [\"lr\", \"Liberia\", \"231\"],\n [\"ly\", \"Libya\", \"218\"],\n [\"li\", \"Liechtenstein\", \"423\"],\n [\"lt\", \"Lithuania\", \"370\"],\n [\"lu\", \"Luxembourg\", \"352\"],\n [\"mo\", \"Macao\", \"853\"],\n [\"mg\", \"Madagascar\", \"261\"],\n [\"mw\", \"Malawi\", \"265\"],\n [\"my\", \"Malaysia\", \"60\"],\n [\"mv\", \"Maldives\", \"960\"],\n [\"ml\", \"Mali\", \"223\"],\n [\"mt\", \"Malta\", \"356\"],\n [\"mq\", \"Martinique\", \"596\"],\n [\"mr\", \"Mauritania\", \"222\"],\n [\"mu\", \"Mauritius\", \"230\"],\n [\"mx\", \"Mexico\", \"52\"],\n [\"md\", \"Moldova\", \"373\"],\n [\"mc\", \"Monaco\", \"377\"],\n [\"mn\", \"Mongolia\", \"976\"],\n [\"me\", \"Montenegro\", \"382\"],\n [\"ma\", \"Morocco\", \"212\"],\n [\"mz\", \"Mozambique\", \"258\"],\n [\"mm\", \"Myanmar\", \"95\"],\n [\"na\", \"Namibia\", \"264\"],\n [\"np\", \"Nepal\", \"977\"],\n [\"nl\", \"Netherlands\", \"31\"],\n [\"nc\", \"New Caledonia\", \"687\"],\n [\"nz\", \"New Zealand\", \"64\"],\n [\"ni\", \"Nicaragua\", \"505\"],\n [\"ne\", \"Niger\", \"227\"],\n [\"ng\", \"Nigeria\", \"234\"],\n [\"kp\", \"North Korea\", \"850\"],\n [\"mk\", \"North Macedonia\", \"389\"],\n [\"no\", \"Norway\", \"47\"],\n [\"om\", \"Oman\", \"968\"],\n [\"pk\", \"Pakistan\", \"92\"],\n [\"ps\", \"Palestine\", \"970\"],\n [\"pa\", \"Panama\", \"507\"],\n [\"pg\", \"Papua New Guinea\", \"675\"],\n [\"py\", \"Paraguay\", \"595\"],\n [\"pe\", \"Peru\", \"51\"],\n [\"ph\", \"Philippines\", \"63\"],\n [\"pl\", \"Poland\", \"48\"],\n [\"pt\", \"Portugal\", \"351\"],\n [\"qa\", \"Qatar\", \"974\"],\n [\"re\", \"Réunion\", \"262\"],\n [\"ro\", \"Romania\", \"40\"],\n [\"ru\", \"Russia / Kazakhstan\", \"7\"],\n [\"rw\", \"Rwanda\", \"250\"],\n [\"ws\", \"Samoa\", \"685\"],\n [\"sm\", \"San Marino\", \"378\"],\n [\"st\", \"São Tomé and Príncipe\", \"239\"],\n [\"sa\", \"Saudi Arabia\", \"966\"],\n [\"sn\", \"Senegal\", \"221\"],\n [\"rs\", \"Serbia\", \"381\"],\n [\"sc\", \"Seychelles\", \"248\"],\n [\"sl\", \"Sierra Leone\", \"232\"],\n [\"sg\", \"Singapore\", \"65\"],\n [\"sk\", \"Slovakia\", \"421\"],\n [\"si\", \"Slovenia\", \"386\"],\n [\"sb\", \"Solomon Islands\", \"677\"],\n [\"so\", \"Somalia\", \"252\"],\n [\"za\", \"South Africa\", \"27\"],\n [\"kr\", \"South Korea\", \"82\"],\n [\"ss\", \"South Sudan\", \"211\"],\n [\"es\", \"Spain\", \"34\"],\n [\"lk\", \"Sri Lanka\", \"94\"],\n [\"sd\", \"Sudan\", \"249\"],\n [\"sr\", \"Suriname\", \"597\"],\n [\"se\", \"Sweden\", \"46\"],\n [\"ch\", \"Switzerland\", \"41\"],\n [\"sy\", \"Syria\", \"963\"],\n [\"tw\", \"Taiwan\", \"886\"],\n [\"tj\", \"Tajikistan\", \"992\"],\n [\"tz\", \"Tanzania\", \"255\"],\n [\"th\", \"Thailand\", \"66\"],\n [\"tl\", \"Timor-Leste\", \"670\"],\n [\"tg\", \"Togo\", \"228\"],\n [\"to\", \"Tonga\", \"676\"],\n [\"tn\", \"Tunisia\", \"216\"],\n [\"tr\", \"Türkiye\", \"90\"],\n [\"tm\", \"Turkmenistan\", \"993\"],\n [\"ug\", \"Uganda\", \"256\"],\n [\"ua\", \"Ukraine\", \"380\"],\n [\"ae\", \"United Arab Emirates\", \"971\"],\n [\"gb\", \"United Kingdom\", \"44\"],\n [\"us\", \"United States / Canada\", \"1\"],\n [\"uy\", \"Uruguay\", \"598\"],\n [\"uz\", \"Uzbekistan\", \"998\"],\n [\"vu\", \"Vanuatu\", \"678\"],\n [\"ve\", \"Venezuela\", \"58\"],\n [\"vn\", \"Vietnam\", \"84\"],\n [\"ye\", \"Yemen\", \"967\"],\n [\"zm\", \"Zambia\", \"260\"],\n [\"zw\", \"Zimbabwe\", \"263\"],\n];\n\n/** Egypt's own numbers: ten digits, starting with 1. */\nconst EGYPT_RULE = { limit: 10, startingNumber: 1 };\n\n/** Every dial code, by country name: what `PhoneInput` lists when no `countries`, `loadCountries` or `endpoint` is given. */\nexport const ALL_PHONE_COUNTRIES: PhoneCountry[] = ROWS.map(([iso, name, code]) => ({\n code,\n name,\n flag: `https://flagcdn.com/${iso}.svg`,\n ...(code === \"20\" ? EGYPT_RULE : {}),\n}));\n\n/** The country selected when nothing else is: Egypt (+20). */\nexport const DEFAULT_PHONE_CODE = \"20\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,WAAW,SAAS,QAAQ,gBAAgC;;;ACKrE,IAAM,OAAmC;AAAA,EACvC,CAAC,MAAM,eAAe,IAAI;AAAA,EAC1B,CAAC,MAAM,WAAW,KAAK;AAAA,EACvB,CAAC,MAAM,WAAW,KAAK;AAAA,EACvB,CAAC,MAAM,WAAW,KAAK;AAAA,EACvB,CAAC,MAAM,UAAU,KAAK;AAAA,EACtB,CAAC,MAAM,aAAa,IAAI;AAAA,EACxB,CAAC,MAAM,WAAW,KAAK;AAAA,EACvB,CAAC,MAAM,SAAS,KAAK;AAAA,EACrB,CAAC,MAAM,aAAa,IAAI;AAAA,EACxB,CAAC,MAAM,WAAW,IAAI;AAAA,EACtB,CAAC,MAAM,cAAc,KAAK;AAAA,EAC1B,CAAC,MAAM,WAAW,KAAK;AAAA,EACvB,CAAC,MAAM,cAAc,KAAK;AAAA,EAC1B,CAAC,MAAM,WAAW,KAAK;AAAA,EACvB,CAAC,MAAM,WAAW,IAAI;AAAA,EACtB,CAAC,MAAM,UAAU,KAAK;AAAA,EACtB,CAAC,MAAM,SAAS,KAAK;AAAA,EACrB,CAAC,MAAM,UAAU,KAAK;AAAA,EACtB,CAAC,MAAM,WAAW,KAAK;AAAA,EACvB,CAAC,MAAM,0BAA0B,KAAK;AAAA,EACtC,CAAC,MAAM,YAAY,KAAK;AAAA,EACxB,CAAC,MAAM,UAAU,IAAI;AAAA,EACrB,CAAC,MAAM,UAAU,KAAK;AAAA,EACtB,CAAC,MAAM,YAA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,UAED,WAAW,SAAS,KAAK,oBAAC,cAAY,GAAG,UAAU,OAAO,GAAG,aAAS,MAAE,qBAAU;AAAA,WACrF;AAAA,QAED,YAAY,oBAAC,WAAM,MAAK,UAAS,MAAM,UAAU,OAAO,MAAM;AAAA,QAC9D,aAAa,oBAAC,WAAM,MAAK,UAAS,MAAM,WAAW,OAAO,SAAS,IAAI;AAAA,QACvE,sBAAsB,oBAAC,WAAM,MAAK,UAAS,MAAM,oBAAoB,OAAO,kBAAkB,IAAI;AAAA;AAAA;AAAA,EACrG;AAEJ,CAAC;AACD,WAAW,cAAc;","names":[]}
@@ -1,192 +0,0 @@
1
- "use client";
2
- import {
3
- ColorPicker,
4
- convertHsvaTo,
5
- isColorValid,
6
- parseColor
7
- } from "./chunk-VIO22OUP.js";
8
- import {
9
- ColorSwatch
10
- } from "./chunk-MWYGXAJQ.js";
11
- import {
12
- InputBase
13
- } from "./chunk-JJXJXOZ7.js";
14
- import {
15
- ActionIcon
16
- } from "./chunk-YFBYWNYF.js";
17
- import {
18
- Popover,
19
- PopoverDropdown,
20
- PopoverTarget
21
- } from "./chunk-K2Q5Q6WQ.js";
22
- import {
23
- factory
24
- } from "./chunk-CJ7I6UM7.js";
25
- import {
26
- useProps,
27
- useStyles
28
- } from "./chunk-4QBFXTYH.js";
29
- import {
30
- useWelloLabels,
31
- useWelloTheme
32
- } from "./chunk-IK562BNJ.js";
33
-
34
- // src/components/ColorPicker/ColorInput.tsx
35
- import { useEffect, useRef, useState } from "react";
36
- import { jsx, jsxs } from "react/jsx-runtime";
37
- var PREVIEW_SIZE = { xs: 16, sm: 18, md: 22, lg: 28, xl: 36 };
38
- var ICON_SIZE = { xs: 14, sm: 16, md: 18, lg: 20, xl: 22 };
39
- function EyeDropperIcon({ size, ...props }) {
40
- return /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", width: size, height: size, fill: "none", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", ...props, children: [
41
- /* @__PURE__ */ jsx("path", { d: "M11 7l6 6" }),
42
- /* @__PURE__ */ jsx("path", { d: "M4 16l11.7-11.7a1 1 0 0 1 1.4 0l2.6 2.6a1 1 0 0 1 0 1.4L8 20H4v-4z" })
43
- ] });
44
- }
45
- var ColorInput = factory((_props, ref) => {
46
- const props = useProps("ColorInput", { format: "hex", fixOnBlur: true, withPreview: true, swatchesPerRow: 7, withPicker: true, withEyeDropper: true, size: "sm" }, _props);
47
- const {
48
- classNames,
49
- styles,
50
- unstyled,
51
- vars,
52
- attributes,
53
- disallowInput,
54
- fixOnBlur,
55
- popoverProps,
56
- withPreview,
57
- withEyeDropper,
58
- eyeDropperIcon,
59
- eyeDropperButtonProps,
60
- closeOnColorSwatchClick,
61
- value,
62
- defaultValue,
63
- onChange,
64
- onChangeEnd,
65
- onFocus,
66
- onBlur,
67
- onClick,
68
- format = "hex",
69
- readOnly,
70
- withPicker,
71
- swatches,
72
- swatchesPerRow,
73
- disabled,
74
- leftSection,
75
- rightSection,
76
- size,
77
- fullWidth,
78
- ...others
79
- } = props;
80
- const labels = useWelloLabels();
81
- const theme = useWelloTheme();
82
- const partClasses = typeof classNames === "function" ? classNames(theme, props) : classNames;
83
- const partStyles = typeof styles === "function" ? styles(theme, props) : styles;
84
- const getStyles = useStyles({ name: "ColorInput", props, classNames: partClasses, styles: partStyles, unstyled, vars, attributes, rootSelector: "wrapper" });
85
- const [opened, setOpened] = useState(false);
86
- const [internal, setInternal] = useState(defaultValue ?? "");
87
- const current = value !== void 0 ? value : internal;
88
- const setValue = (next) => {
89
- if (value === void 0) setInternal(next);
90
- onChange?.(next);
91
- };
92
- const lastValid = useRef("");
93
- useEffect(() => {
94
- if (isColorValid(current) || current.trim() === "") lastValid.current = current;
95
- }, [current]);
96
- const lastFormat = useRef(format);
97
- useEffect(() => {
98
- if (lastFormat.current === format) return;
99
- lastFormat.current = format;
100
- if (isColorValid(current)) setValue(convertHsvaTo(format, parseColor(current)));
101
- }, [format]);
102
- const [eyeDropperSupported, setSupported] = useState(false);
103
- useEffect(() => setSupported(typeof window !== "undefined" && "EyeDropper" in window), []);
104
- const named = typeof size === "string" ? size : "sm";
105
- return /* @__PURE__ */ jsxs(Popover, { position: "bottom-start", offset: 5, opened, width: fullWidth ? "target" : void 0, transitionProps: { duration: 0 }, ...popoverProps, withRoles: false, disabled: readOnly || withPicker === false && !swatches?.length, children: [
106
- /* @__PURE__ */ jsx(PopoverTarget, { children: /* @__PURE__ */ jsx(
107
- InputBase,
108
- {
109
- autoComplete: "off",
110
- spellCheck: false,
111
- ...others,
112
- __staticSelector: "ColorInput",
113
- ref,
114
- classNames: partClasses,
115
- styles: partStyles,
116
- unstyled,
117
- size,
118
- disabled,
119
- readOnly: disallowInput || readOnly,
120
- pointer: disallowInput,
121
- value: current,
122
- onFocus: (event) => {
123
- onFocus?.(event);
124
- setOpened(true);
125
- },
126
- onBlur: (event) => {
127
- if (fixOnBlur && current !== lastValid.current) setValue(lastValid.current);
128
- onBlur?.(event);
129
- setOpened(false);
130
- },
131
- onClick: (event) => {
132
- onClick?.(event);
133
- setOpened(true);
134
- },
135
- onChange: (event) => {
136
- const next = event.currentTarget.value;
137
- setValue(next);
138
- if (isColorValid(next)) onChangeEnd?.(convertHsvaTo(format, parseColor(next)));
139
- },
140
- leftSection: leftSection || (withPreview ? /* @__PURE__ */ jsx(ColorSwatch, { color: isColorValid(current) ? current : "#fff", size: PREVIEW_SIZE[named] ?? 18, ...getStyles("colorPreview") }) : null),
141
- rightSectionPointerEvents: "auto",
142
- rightSection: rightSection || (withEyeDropper && !disabled && !readOnly && eyeDropperSupported ? /* @__PURE__ */ jsx(
143
- ActionIcon,
144
- {
145
- "aria-label": labels.colorEyeDropper,
146
- ...eyeDropperButtonProps,
147
- ...getStyles("eyeDropperButton"),
148
- variant: "subtle",
149
- color: "gray",
150
- onMouseDown: (event) => event.preventDefault(),
151
- onClick: () => {
152
- const EyeDropper = window.EyeDropper;
153
- new EyeDropper().open().then(({ sRGBHex }) => {
154
- const color = convertHsvaTo(format, parseColor(sRGBHex));
155
- setValue(color);
156
- onChangeEnd?.(color);
157
- }).catch(() => void 0);
158
- },
159
- children: eyeDropperIcon || /* @__PURE__ */ jsx(EyeDropperIcon, { size: ICON_SIZE[named] ?? 16, ...getStyles("eyeDropperIcon") })
160
- }
161
- ) : null)
162
- }
163
- ) }),
164
- /* @__PURE__ */ jsx(PopoverDropdown, { ...getStyles("dropdown"), onMouseDown: (event) => event.preventDefault(), children: /* @__PURE__ */ jsx(
165
- ColorPicker,
166
- {
167
- value: current,
168
- onChange: setValue,
169
- onChangeEnd,
170
- format,
171
- swatches,
172
- swatchesPerRow,
173
- withPicker,
174
- size,
175
- focusable: false,
176
- unstyled,
177
- classNames: partClasses,
178
- styles: partStyles,
179
- fullWidth,
180
- onColorSwatchClick: () => {
181
- if (closeOnColorSwatchClick) setOpened(false);
182
- }
183
- }
184
- ) })
185
- ] });
186
- });
187
- ColorInput.displayName = "ColorInput";
188
-
189
- export {
190
- ColorInput
191
- };
192
- //# sourceMappingURL=chunk-YHPHWOAE.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/components/ColorPicker/ColorInput.tsx"],"sourcesContent":["import { useEffect, useRef, useState, type ReactNode } from \"react\";\nimport { factory } from \"../../core/factory/factory\";\nimport { useWelloLabels } from \"../../core/provider/labels\";\nimport { useWelloTheme } from \"../../core/provider/WelloProvider\";\nimport { useProps, useStyles, type StylesApiProps } from \"../../core/styles-api/styles-api\";\nimport { ActionIcon } from \"../ActionIcon/ActionIcon\";\nimport { InputBase, type InputBaseProps, type InputStylesNames, type InputWrapperStylesNames } from \"../Input/Input\";\nimport { Popover, PopoverDropdown, PopoverTarget, type PopoverProps } from \"../Popover/Popover\";\nimport { ColorSwatch } from \"../ThemeIcon/ThemeIcon\";\nimport { convertHsvaTo, isColorValid, parseColor } from \"./color-converters\";\nimport { ColorPicker, type ColorPickerBaseProps, type ColorPickerStylesNames } from \"./ColorPicker\";\n\nexport type ColorInputStylesNames = \"dropdown\" | \"eyeDropperButton\" | \"eyeDropperIcon\" | \"colorPreview\" | ColorPickerStylesNames | InputStylesNames | InputWrapperStylesNames;\n\nexport interface ColorInputProps extends Omit<InputBaseProps, \"value\" | \"defaultValue\" | \"onChange\" | \"size\" | keyof StylesApiProps<string>>, ColorPickerBaseProps, StylesApiProps<ColorInputStylesNames, ColorInputProps> {\n placeholder?: string;\n name?: string;\n readOnly?: boolean;\n /** Only the picker and swatches can change it */\n disallowInput?: boolean;\n /** Back to the last valid color on blur. Default: true */\n fixOnBlur?: boolean;\n popoverProps?: Partial<PopoverProps>;\n /** Color sample on the left. Default: true */\n withPreview?: boolean;\n /** Button to pick from the screen, where the browser supports it. Default: true */\n withEyeDropper?: boolean;\n eyeDropperIcon?: ReactNode;\n eyeDropperButtonProps?: Record<string, unknown>;\n /** Clicking a swatch closes the dropdown */\n closeOnColorSwatchClick?: boolean;\n onFocus?: React.FocusEventHandler<HTMLInputElement>;\n onBlur?: React.FocusEventHandler<HTMLInputElement>;\n onClick?: React.MouseEventHandler<HTMLInputElement>;\n}\n\nconst PREVIEW_SIZE: Record<string, number> = { xs: 16, sm: 18, md: 22, lg: 28, xl: 36 };\nconst ICON_SIZE: Record<string, number> = { xs: 14, sm: 16, md: 18, lg: 20, xl: 22 };\n\nfunction EyeDropperIcon({ size, ...props }: { size: number } & React.SVGProps<SVGSVGElement>) {\n return (\n <svg viewBox=\"0 0 24 24\" width={size} height={size} fill=\"none\" stroke=\"currentColor\" strokeWidth={1.5} strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" {...props}>\n <path d=\"M11 7l6 6\" />\n <path d=\"M4 16l11.7-11.7a1 1 0 0 1 1.4 0l2.6 2.6a1 1 0 0 1 0 1.4L8 20H4v-4z\" />\n </svg>\n );\n}\n\ntype EyeDropperConstructor = new () => { open: () => Promise<{ sRGBHex: string }> };\n\n/**\n * Text field with a color picker in a dropdown.\n *\n * @example\n * <ColorInput label=\"Brand color\" value={color} onChange={setColor} />\n * <ColorInput {...field} format=\"rgba\" swatches={[\"#2563eb\", \"#dc2626\"]} />\n */\nexport const ColorInput = factory<{ props: ColorInputProps; ref: HTMLInputElement; stylesNames: ColorInputStylesNames }>((_props, ref) => {\n const props = useProps(\"ColorInput\", { format: \"hex\", fixOnBlur: true, withPreview: true, swatchesPerRow: 7, withPicker: true, withEyeDropper: true, size: \"sm\" }, _props);\n const {\n classNames,\n styles,\n unstyled,\n vars,\n attributes,\n disallowInput,\n fixOnBlur,\n popoverProps,\n withPreview,\n withEyeDropper,\n eyeDropperIcon,\n eyeDropperButtonProps,\n closeOnColorSwatchClick,\n value,\n defaultValue,\n onChange,\n onChangeEnd,\n onFocus,\n onBlur,\n onClick,\n format = \"hex\",\n readOnly,\n withPicker,\n swatches,\n swatchesPerRow,\n disabled,\n leftSection,\n rightSection,\n size,\n fullWidth,\n ...others\n } = props;\n const labels = useWelloLabels();\n const theme = useWelloTheme();\n const partClasses = typeof classNames === \"function\" ? classNames(theme, props) : classNames;\n const partStyles = typeof styles === \"function\" ? styles(theme, props) : styles;\n const getStyles = useStyles<ColorInputStylesNames, ColorInputProps>({ name: \"ColorInput\", props, classNames: partClasses, styles: partStyles, unstyled, vars, attributes, rootSelector: \"wrapper\" });\n\n const [opened, setOpened] = useState(false);\n const [internal, setInternal] = useState(defaultValue ?? \"\");\n const current = value !== undefined ? value : internal;\n const setValue = (next: string) => {\n if (value === undefined) setInternal(next);\n onChange?.(next);\n };\n const lastValid = useRef(\"\");\n useEffect(() => {\n if (isColorValid(current) || current.trim() === \"\") lastValid.current = current;\n }, [current]);\n\n // Compared, not \"skip the first run\": StrictMode runs effects twice on mount.\n const lastFormat = useRef(format);\n useEffect(() => {\n if (lastFormat.current === format) return;\n lastFormat.current = format;\n if (isColorValid(current)) setValue(convertHsvaTo(format, parseColor(current)));\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [format]);\n\n // Checked after mount, so the server and the browser render the same thing.\n const [eyeDropperSupported, setSupported] = useState(false);\n useEffect(() => setSupported(typeof window !== \"undefined\" && \"EyeDropper\" in window), []);\n const named = typeof size === \"string\" ? size : \"sm\";\n\n return (\n <Popover position=\"bottom-start\" offset={5} opened={opened} width={fullWidth ? \"target\" : undefined} transitionProps={{ duration: 0 }} {...popoverProps} withRoles={false} disabled={readOnly || (withPicker === false && !swatches?.length)}>\n <PopoverTarget>\n <InputBase\n autoComplete=\"off\"\n spellCheck={false}\n {...(others as object)}\n __staticSelector=\"ColorInput\"\n ref={ref}\n classNames={partClasses}\n styles={partStyles}\n unstyled={unstyled}\n size={size}\n disabled={disabled}\n readOnly={disallowInput || readOnly}\n pointer={disallowInput}\n value={current}\n onFocus={(event: React.FocusEvent<HTMLInputElement>) => {\n onFocus?.(event);\n setOpened(true);\n }}\n onBlur={(event: React.FocusEvent<HTMLInputElement>) => {\n if (fixOnBlur && current !== lastValid.current) setValue(lastValid.current);\n onBlur?.(event);\n setOpened(false);\n }}\n onClick={(event: React.MouseEvent<HTMLInputElement>) => {\n onClick?.(event);\n setOpened(true);\n }}\n onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n const next = event.currentTarget.value;\n setValue(next);\n if (isColorValid(next)) onChangeEnd?.(convertHsvaTo(format, parseColor(next)));\n }}\n leftSection={leftSection || (withPreview ? <ColorSwatch color={isColorValid(current) ? current : \"#fff\"} size={PREVIEW_SIZE[named] ?? 18} {...getStyles(\"colorPreview\")} /> : null)}\n rightSectionPointerEvents=\"auto\"\n rightSection={\n rightSection ||\n (withEyeDropper && !disabled && !readOnly && eyeDropperSupported ? (\n <ActionIcon\n aria-label={labels.colorEyeDropper}\n {...eyeDropperButtonProps}\n {...getStyles(\"eyeDropperButton\")}\n variant=\"subtle\"\n color=\"gray\"\n onMouseDown={(event: React.MouseEvent) => event.preventDefault()}\n onClick={() => {\n const EyeDropper = (window as unknown as { EyeDropper: EyeDropperConstructor }).EyeDropper;\n new EyeDropper()\n .open()\n .then(({ sRGBHex }) => {\n const color = convertHsvaTo(format, parseColor(sRGBHex));\n setValue(color);\n onChangeEnd?.(color);\n })\n .catch(() => undefined);\n }}\n >\n {eyeDropperIcon || <EyeDropperIcon size={ICON_SIZE[named] ?? 16} {...(getStyles(\"eyeDropperIcon\") as object)} />}\n </ActionIcon>\n ) : null)\n }\n />\n </PopoverTarget>\n <PopoverDropdown {...getStyles(\"dropdown\")} onMouseDown={(event: React.MouseEvent) => event.preventDefault()}>\n <ColorPicker\n value={current}\n onChange={setValue}\n onChangeEnd={onChangeEnd}\n format={format}\n swatches={swatches}\n swatchesPerRow={swatchesPerRow}\n withPicker={withPicker}\n size={size}\n focusable={false}\n unstyled={unstyled}\n classNames={partClasses as never}\n styles={partStyles as never}\n fullWidth={fullWidth}\n onColorSwatchClick={() => {\n if (closeOnColorSwatchClick) setOpened(false);\n }}\n />\n </PopoverDropdown>\n </Popover>\n );\n});\nColorInput.displayName = \"ColorInput\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,WAAW,QAAQ,gBAAgC;AAyCxD,SACE,KADF;AALJ,IAAM,eAAuC,EAAE,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,GAAG;AACtF,IAAM,YAAoC,EAAE,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,GAAG;AAEnF,SAAS,eAAe,EAAE,MAAM,GAAG,MAAM,GAAqD;AAC5F,SACE,qBAAC,SAAI,SAAQ,aAAY,OAAO,MAAM,QAAQ,MAAM,MAAK,QAAO,QAAO,gBAAe,aAAa,KAAK,eAAc,SAAQ,gBAAe,SAAQ,eAAY,QAAQ,GAAG,OAC1K;AAAA,wBAAC,UAAK,GAAE,aAAY;AAAA,IACpB,oBAAC,UAAK,GAAE,sEAAqE;AAAA,KAC/E;AAEJ;AAWO,IAAM,aAAa,QAA+F,CAAC,QAAQ,QAAQ;AACxI,QAAM,QAAQ,SAAS,cAAc,EAAE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