@radix-ui/react-password-toggle-field 0.1.10 → 0.1.11
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 +2 -7
- package/dist/index.d.ts +2 -7
- package/dist/index.js +1 -5
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +1 -5
- package/dist/index.mjs.map +2 -2
- package/package.json +12 -12
- package/src/password-toggle-field.tsx +3 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { PrimitivePropsWithRef } from '@radix-ui/react-primitive';
|
|
3
3
|
|
|
4
|
-
declare const AutoComplete: {
|
|
5
|
-
readonly CurrentPassword: "current-password";
|
|
6
|
-
readonly NewPassword: "new-password";
|
|
7
|
-
};
|
|
8
|
-
type AutoComplete = (typeof AutoComplete)[keyof typeof AutoComplete];
|
|
9
4
|
interface PasswordToggleFieldProps {
|
|
10
5
|
id?: string;
|
|
11
6
|
visible?: boolean;
|
|
@@ -16,10 +11,10 @@ interface PasswordToggleFieldProps {
|
|
|
16
11
|
declare const PasswordToggleField: React.FC<PasswordToggleFieldProps>;
|
|
17
12
|
type PrimitiveInputProps = PrimitivePropsWithRef<'input'>;
|
|
18
13
|
interface PasswordToggleFieldOwnProps {
|
|
19
|
-
autoComplete?:
|
|
14
|
+
autoComplete?: 'current-password' | 'new-password';
|
|
20
15
|
}
|
|
21
16
|
interface PasswordToggleFieldInputProps extends PasswordToggleFieldOwnProps, Omit<PrimitiveInputProps, keyof PasswordToggleFieldOwnProps | 'type'> {
|
|
22
|
-
autoComplete?:
|
|
17
|
+
autoComplete?: 'current-password' | 'new-password';
|
|
23
18
|
}
|
|
24
19
|
declare const PasswordToggleFieldInput: React.ForwardRefExoticComponent<Omit<PasswordToggleFieldInputProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
|
|
25
20
|
type PrimitiveButtonProps = PrimitivePropsWithRef<'button'>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { PrimitivePropsWithRef } from '@radix-ui/react-primitive';
|
|
3
3
|
|
|
4
|
-
declare const AutoComplete: {
|
|
5
|
-
readonly CurrentPassword: "current-password";
|
|
6
|
-
readonly NewPassword: "new-password";
|
|
7
|
-
};
|
|
8
|
-
type AutoComplete = (typeof AutoComplete)[keyof typeof AutoComplete];
|
|
9
4
|
interface PasswordToggleFieldProps {
|
|
10
5
|
id?: string;
|
|
11
6
|
visible?: boolean;
|
|
@@ -16,10 +11,10 @@ interface PasswordToggleFieldProps {
|
|
|
16
11
|
declare const PasswordToggleField: React.FC<PasswordToggleFieldProps>;
|
|
17
12
|
type PrimitiveInputProps = PrimitivePropsWithRef<'input'>;
|
|
18
13
|
interface PasswordToggleFieldOwnProps {
|
|
19
|
-
autoComplete?:
|
|
14
|
+
autoComplete?: 'current-password' | 'new-password';
|
|
20
15
|
}
|
|
21
16
|
interface PasswordToggleFieldInputProps extends PasswordToggleFieldOwnProps, Omit<PrimitiveInputProps, keyof PasswordToggleFieldOwnProps | 'type'> {
|
|
22
|
-
autoComplete?:
|
|
17
|
+
autoComplete?: 'current-password' | 'new-password';
|
|
23
18
|
}
|
|
24
19
|
declare const PasswordToggleFieldInput: React.ForwardRefExoticComponent<Omit<PasswordToggleFieldInputProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
|
|
25
20
|
type PrimitiveButtonProps = PrimitivePropsWithRef<'button'>;
|
package/dist/index.js
CHANGED
|
@@ -59,10 +59,6 @@ var import_react_use_effect_event = require("@radix-ui/react-use-effect-event");
|
|
|
59
59
|
var import_react_context = require("@radix-ui/react-context");
|
|
60
60
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
61
61
|
var PASSWORD_TOGGLE_FIELD_NAME = "PasswordToggleField";
|
|
62
|
-
var AutoComplete = {
|
|
63
|
-
CurrentPassword: "current-password",
|
|
64
|
-
NewPassword: "new-password"
|
|
65
|
-
};
|
|
66
62
|
var [createPasswordToggleFieldContext] = (0, import_react_context.createContextScope)(PASSWORD_TOGGLE_FIELD_NAME);
|
|
67
63
|
var [PasswordToggleFieldProvider, usePasswordToggleFieldContext] = createPasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_NAME);
|
|
68
64
|
var INITIAL_FOCUS_STATE = {
|
|
@@ -127,7 +123,7 @@ var PasswordToggleFieldInput = /* @__PURE__ */ React.forwardRef(
|
|
|
127
123
|
// blank line to reduce diff noise
|
|
128
124
|
/* @__PURE__ */ __name(function PasswordToggleFieldInput2({
|
|
129
125
|
__scopePasswordToggleField,
|
|
130
|
-
autoComplete =
|
|
126
|
+
autoComplete = "current-password",
|
|
131
127
|
autoCapitalize = "off",
|
|
132
128
|
spellCheck = false,
|
|
133
129
|
id: idProp,
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/password-toggle-field.tsx"],
|
|
4
|
-
"sourcesContent": ["'use client';\nexport type {\n PasswordToggleFieldProps,\n PasswordToggleFieldInputProps,\n PasswordToggleFieldToggleProps,\n PasswordToggleFieldIconProps,\n PasswordToggleFieldSlotProps,\n} from './password-toggle-field';\nexport {\n PasswordToggleField,\n PasswordToggleFieldInput,\n PasswordToggleFieldToggle,\n PasswordToggleFieldIcon,\n PasswordToggleFieldSlot,\n //\n Root,\n Input,\n Toggle,\n Icon,\n Slot,\n} from './password-toggle-field';\n", "import * as React from 'react';\nimport { flushSync } from 'react-dom';\nimport { IS_DEVELOPMENT } from '@radix-ui/primitive/is-development';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { Primitive, type PrimitivePropsWithRef } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useId } from '@radix-ui/react-id';\nimport { useIsHydrated } from '@radix-ui/react-use-is-hydrated';\nimport { useEffectEvent } from '@radix-ui/react-use-effect-event';\nimport type { Scope } from '@radix-ui/react-context';\nimport { createContextScope } from '@radix-ui/react-context';\n\nconst PASSWORD_TOGGLE_FIELD_NAME = 'PasswordToggleField';\n\nconst AutoComplete = {\n CurrentPassword: 'current-password',\n NewPassword: 'new-password',\n} as const;\n\ntype AutoComplete = (typeof AutoComplete)[keyof typeof AutoComplete];\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldProvider\n * -----------------------------------------------------------------------------------------------*/\n\ntype InternalFocusState = {\n clickTriggered: boolean;\n selectionStart: number | null;\n selectionEnd: number | null;\n};\n\ninterface PasswordToggleFieldContextValue {\n inputId: string;\n inputRef: React.RefObject<HTMLInputElement | null>;\n visible: boolean;\n setVisible: React.Dispatch<React.SetStateAction<boolean>>;\n syncInputId: (providedId: string | number | undefined) => void;\n focusState: React.RefObject<InternalFocusState>;\n}\n\nconst [createPasswordToggleFieldContext] = createContextScope(PASSWORD_TOGGLE_FIELD_NAME);\nconst [PasswordToggleFieldProvider, usePasswordToggleFieldContext] =\n createPasswordToggleFieldContext<PasswordToggleFieldContextValue>(PASSWORD_TOGGLE_FIELD_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleField\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopedProps<P> = P & { __scopePasswordToggleField?: Scope };\n\ninterface PasswordToggleFieldProps {\n id?: string;\n visible?: boolean;\n defaultVisible?: boolean;\n onVisibilityChange?: (visible: boolean) => void;\n children?: React.ReactNode;\n}\n\nconst INITIAL_FOCUS_STATE: InternalFocusState = {\n clickTriggered: false,\n selectionStart: null,\n selectionEnd: null,\n};\n\nconst PasswordToggleField: React.FC<PasswordToggleFieldProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldProps>) => {\n const baseId = useId(props.id);\n const defaultInputId = `${baseId}-input`;\n const [inputIdState, setInputIdState] = React.useState<null | string>(defaultInputId);\n const inputId = inputIdState ?? defaultInputId;\n const syncInputId = React.useCallback(\n (providedId: string | number | undefined) =>\n setInputIdState(providedId != null ? String(providedId) : null),\n [],\n );\n\n const { visible: visibleProp, defaultVisible, children } = props;\n\n let onVisibilityChange = props.onVisibilityChange;\n let shouldWarn = false;\n if (\n !onVisibilityChange &&\n 'onVisiblityChange' in props &&\n typeof props.onVisiblityChange === 'function'\n ) {\n shouldWarn = true;\n onVisibilityChange = props.onVisiblityChange as (visible: boolean) => void;\n } else {\n onVisibilityChange = props.onVisibilityChange;\n }\n\n if (IS_DEVELOPMENT) {\n // oxlint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (shouldWarn) {\n console.warn(\n 'PasswordToggleField: The misspelled `onVisiblityChange` prop has been removed. Please use `onVisibilityChange` instead.',\n );\n }\n }, [shouldWarn]);\n }\n\n const [visible = false, setVisible] = useControllableState({\n caller: PASSWORD_TOGGLE_FIELD_NAME,\n prop: visibleProp,\n defaultProp: defaultVisible ?? false,\n onChange: onVisibilityChange,\n });\n\n const inputRef = React.useRef<HTMLInputElement | null>(null);\n const focusState = React.useRef<InternalFocusState>(INITIAL_FOCUS_STATE);\n\n return (\n <PasswordToggleFieldProvider\n scope={__scopePasswordToggleField}\n inputId={inputId}\n inputRef={inputRef}\n setVisible={setVisible}\n syncInputId={syncInputId}\n visible={visible}\n focusState={focusState}\n >\n {children}\n </PasswordToggleFieldProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_INPUT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Input';\n\ntype PrimitiveInputProps = PrimitivePropsWithRef<'input'>;\n\ninterface PasswordToggleFieldOwnProps {\n autoComplete?: AutoComplete;\n}\n\ninterface PasswordToggleFieldInputProps\n extends\n PasswordToggleFieldOwnProps,\n Omit<PrimitiveInputProps, keyof PasswordToggleFieldOwnProps | 'type'> {\n autoComplete?: AutoComplete;\n}\n\nconst PasswordToggleFieldInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n PasswordToggleFieldInputProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldInput(\n {\n __scopePasswordToggleField,\n autoComplete = AutoComplete.CurrentPassword,\n autoCapitalize = 'off',\n spellCheck = false,\n id: idProp,\n ...props\n }: ScopedProps<PasswordToggleFieldInputProps>,\n forwardedRef,\n ) {\n const { visible, inputRef, inputId, syncInputId, setVisible, focusState } =\n usePasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_INPUT_NAME, __scopePasswordToggleField);\n\n React.useEffect(() => {\n syncInputId(idProp);\n }, [idProp, syncInputId]);\n\n // We want to reset the visibility to `false` to revert the input to\n // `type=\"password\"` when:\n // - The form is reset (for consistency with other form controls)\n // - The form is submitted (to prevent the browser from remembering the\n // input's value.\n //\n // See \"Keeping things secure\":\n // https://technology.blog.gov.uk/2021/04/19/simple-things-are-complicated-making-a-show-password-option/)\n const _setVisible = useEffectEvent(setVisible);\n React.useEffect(() => {\n const inputElement = inputRef.current;\n const form = inputElement?.form;\n if (!form) {\n return;\n }\n\n const controller = new AbortController();\n form.addEventListener(\n 'reset',\n (event) => {\n if (!event.defaultPrevented) {\n _setVisible(false);\n }\n },\n { signal: controller.signal },\n );\n form.addEventListener(\n 'submit',\n () => {\n // always reset the visibility on submit regardless of whether the\n // default action is prevented\n _setVisible(false);\n },\n { signal: controller.signal },\n );\n return () => {\n controller.abort();\n };\n }, [inputRef]);\n\n return (\n <Primitive.input\n {...props}\n id={idProp ?? inputId}\n autoCapitalize={autoCapitalize}\n autoComplete={autoComplete}\n ref={useComposedRefs(forwardedRef, inputRef)}\n spellCheck={spellCheck}\n type={visible ? 'text' : 'password'}\n onBlur={composeEventHandlers(props.onBlur, (event) => {\n // get the cursor position\n const { selectionStart, selectionEnd } = event.currentTarget;\n focusState.current.selectionStart = selectionStart;\n focusState.current.selectionEnd = selectionEnd;\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldToggle\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_TOGGLE_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Toggle';\n\ntype PrimitiveButtonProps = PrimitivePropsWithRef<'button'>;\n\ninterface PasswordToggleFieldToggleProps extends Omit<PrimitiveButtonProps, 'type'> {}\n\nconst PasswordToggleFieldToggle = /* @__PURE__ */ React.forwardRef<\n HTMLButtonElement,\n PasswordToggleFieldToggleProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldToggle(\n {\n __scopePasswordToggleField,\n onClick,\n onPointerDown,\n onPointerCancel,\n onPointerUp,\n onFocus,\n children,\n 'aria-label': ariaLabelProp,\n 'aria-controls': ariaControls,\n 'aria-hidden': ariaHidden,\n tabIndex,\n ...props\n }: ScopedProps<PasswordToggleFieldToggleProps>,\n forwardedRef,\n ) {\n const { setVisible, visible, inputRef, inputId, focusState } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_TOGGLE_NAME,\n __scopePasswordToggleField,\n );\n const [internalAriaLabel, setInternalAriaLabel] = React.useState<string | undefined>(undefined);\n const elementRef = React.useRef<HTMLButtonElement>(null);\n const ref = useComposedRefs(forwardedRef, elementRef);\n const isHydrated = useIsHydrated();\n\n React.useEffect(() => {\n const element = elementRef.current;\n if (!element || ariaLabelProp) {\n setInternalAriaLabel(undefined);\n return;\n }\n\n const DEFAULT_ARIA_LABEL = visible ? 'Hide password' : 'Show password';\n\n function checkForInnerTextLabel(textContent: string | undefined | null) {\n const text = textContent ? textContent : undefined;\n // If the element has inner text, no need to force an aria-label.\n setInternalAriaLabel(text ? undefined : DEFAULT_ARIA_LABEL);\n }\n\n checkForInnerTextLabel(element.textContent);\n\n const observer = new MutationObserver((entries) => {\n let textContent: string | undefined;\n for (const entry of entries) {\n if (entry.type === 'characterData') {\n if (element.textContent) {\n textContent = element.textContent;\n }\n }\n }\n checkForInnerTextLabel(textContent);\n });\n observer.observe(element, { characterData: true, subtree: true });\n return () => {\n observer.disconnect();\n };\n }, [visible, ariaLabelProp]);\n\n const ariaLabel = ariaLabelProp || internalAriaLabel;\n\n // Before hydration the button will not work, but we want to render it\n // regardless to prevent potential layout shift. Hide it from assistive tech\n // by default. Post-hydration it will be visible, focusable and associated\n // with the input via aria-controls.\n if (!isHydrated) {\n ariaHidden ??= true;\n tabIndex ??= -1;\n } else {\n ariaControls ??= inputId;\n }\n\n React.useEffect(() => {\n let cleanup = () => {};\n const ownerWindow = elementRef.current?.ownerDocument?.defaultView || window;\n const reset = () => (focusState.current.clickTriggered = false);\n const handlePointerUp = () => (cleanup = requestIdleCallback(ownerWindow, reset));\n ownerWindow.addEventListener('pointerup', handlePointerUp);\n return () => {\n cleanup();\n ownerWindow.removeEventListener('pointerup', handlePointerUp);\n };\n }, [focusState]);\n\n return (\n <Primitive.button\n aria-controls={ariaControls}\n aria-hidden={ariaHidden}\n aria-label={ariaLabel}\n ref={ref}\n id={inputId}\n {...props}\n onPointerDown={composeEventHandlers(onPointerDown, () => {\n focusState.current.clickTriggered = true;\n })}\n onPointerCancel={(event) => {\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref on cancellation, regardless of whether the user has\n // called preventDefault on the event\n onPointerCancel?.(event);\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref after click, regardless of whether the user has\n // called preventDefault on the event\n onClick={(event) => {\n onClick?.(event);\n if (event.defaultPrevented) {\n focusState.current = INITIAL_FOCUS_STATE;\n return;\n }\n\n flushSync(() => {\n setVisible((s) => !s);\n });\n if (focusState.current.clickTriggered) {\n const input = inputRef.current;\n if (input) {\n const { selectionStart, selectionEnd } = focusState.current;\n input.focus();\n if (selectionStart !== null || selectionEnd !== null) {\n // wait a tick so that focus has settled, then restore select position\n requestAnimationFrame(() => {\n // make sure the input still has focus (developer may have\n // programatically moved focus elsewhere)\n if (input.ownerDocument.activeElement === input) {\n input.selectionStart = selectionStart;\n input.selectionEnd = selectionEnd;\n }\n });\n }\n }\n }\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n onPointerUp={(event) => {\n onPointerUp?.(event);\n // if click handler hasn't been called at this point, it may have been\n // intercepted, in which case we still want to reset our internal\n // state\n setTimeout(() => {\n focusState.current = INITIAL_FOCUS_STATE;\n }, 50);\n }}\n type=\"button\"\n >\n {children}\n </Primitive.button>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldSlot\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_SLOT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Slot';\n\ninterface PasswordToggleFieldSlotDeclarativeProps {\n visible: React.ReactNode;\n hidden: React.ReactNode;\n}\n\ninterface PasswordToggleFieldSlotRenderProps {\n render: (args: { visible: boolean }) => React.ReactElement;\n}\n\ntype PasswordToggleFieldSlotProps =\n | PasswordToggleFieldSlotDeclarativeProps\n | PasswordToggleFieldSlotRenderProps;\n\nconst PasswordToggleFieldSlot: React.FC<PasswordToggleFieldSlotProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldSlotProps>) => {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_SLOT_NAME,\n __scopePasswordToggleField,\n );\n\n return 'render' in props\n ? //\n props.render({ visible })\n : visible\n ? props.visible\n : props.hidden;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldIcon\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_ICON_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Icon';\n\ntype PrimitiveSvgProps = PrimitivePropsWithRef<'svg'>;\n\ninterface PasswordToggleFieldIconProps extends Omit<PrimitiveSvgProps, 'children'> {\n visible: React.ReactElement;\n hidden: React.ReactElement;\n}\n\nconst PasswordToggleFieldIcon = /* @__PURE__ */ React.forwardRef<\n SVGSVGElement,\n PasswordToggleFieldIconProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldIcon(\n {\n __scopePasswordToggleField,\n // @ts-expect-error\n children,\n ...props\n }: ScopedProps<PasswordToggleFieldIconProps>,\n forwardedRef,\n ) {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_ICON_NAME,\n __scopePasswordToggleField,\n );\n const { visible: visibleIcon, hidden: hiddenIcon, ...domProps } = props;\n return (\n <Primitive.svg {...domProps} ref={forwardedRef} aria-hidden asChild>\n {visible ? visibleIcon : hiddenIcon}\n </Primitive.svg>\n );\n },\n);\n\nexport {\n PasswordToggleField,\n PasswordToggleFieldInput,\n PasswordToggleFieldToggle,\n PasswordToggleFieldSlot,\n PasswordToggleFieldIcon,\n //\n PasswordToggleField as Root,\n PasswordToggleFieldInput as Input,\n PasswordToggleFieldToggle as Toggle,\n PasswordToggleFieldSlot as Slot,\n PasswordToggleFieldIcon as Icon,\n};\nexport type {\n PasswordToggleFieldProps,\n PasswordToggleFieldInputProps,\n PasswordToggleFieldToggleProps,\n PasswordToggleFieldIconProps,\n PasswordToggleFieldSlotProps,\n};\n\nfunction requestIdleCallback(\n window: Window,\n callback: IdleRequestCallback,\n options?: IdleRequestOptions,\n): () => void {\n if ((window as any).requestIdleCallback) {\n const id = window.requestIdleCallback(callback, options);\n return () => {\n window.cancelIdleCallback(id);\n };\n }\n const start = Date.now();\n const id = window.setTimeout(() => {\n const timeRemaining = () => Math.max(0, 50 - (Date.now() - start));\n callback({ didTimeout: false, timeRemaining });\n }, 1);\n return () => {\n window.clearTimeout(id);\n };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,uBAA0B;AAC1B,4BAA+B;AAC/B,uBAAqC;AACrC,0CAAqC;AACrC,6BAAsD;AACtD,gCAAgC;AAChC,sBAAsB;AACtB,mCAA8B;AAC9B,oCAA+B;AAE/B,2BAAmC;
|
|
4
|
+
"sourcesContent": ["'use client';\nexport type {\n PasswordToggleFieldProps,\n PasswordToggleFieldInputProps,\n PasswordToggleFieldToggleProps,\n PasswordToggleFieldIconProps,\n PasswordToggleFieldSlotProps,\n} from './password-toggle-field';\nexport {\n PasswordToggleField,\n PasswordToggleFieldInput,\n PasswordToggleFieldToggle,\n PasswordToggleFieldIcon,\n PasswordToggleFieldSlot,\n //\n Root,\n Input,\n Toggle,\n Icon,\n Slot,\n} from './password-toggle-field';\n", "import * as React from 'react';\nimport { flushSync } from 'react-dom';\nimport { IS_DEVELOPMENT } from '@radix-ui/primitive/is-development';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { Primitive, type PrimitivePropsWithRef } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useId } from '@radix-ui/react-id';\nimport { useIsHydrated } from '@radix-ui/react-use-is-hydrated';\nimport { useEffectEvent } from '@radix-ui/react-use-effect-event';\nimport type { Scope } from '@radix-ui/react-context';\nimport { createContextScope } from '@radix-ui/react-context';\n\nconst PASSWORD_TOGGLE_FIELD_NAME = 'PasswordToggleField';\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldProvider\n * -----------------------------------------------------------------------------------------------*/\n\ntype InternalFocusState = {\n clickTriggered: boolean;\n selectionStart: number | null;\n selectionEnd: number | null;\n};\n\ninterface PasswordToggleFieldContextValue {\n inputId: string;\n inputRef: React.RefObject<HTMLInputElement | null>;\n visible: boolean;\n setVisible: React.Dispatch<React.SetStateAction<boolean>>;\n syncInputId: (providedId: string | number | undefined) => void;\n focusState: React.RefObject<InternalFocusState>;\n}\n\nconst [createPasswordToggleFieldContext] = createContextScope(PASSWORD_TOGGLE_FIELD_NAME);\nconst [PasswordToggleFieldProvider, usePasswordToggleFieldContext] =\n createPasswordToggleFieldContext<PasswordToggleFieldContextValue>(PASSWORD_TOGGLE_FIELD_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleField\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopedProps<P> = P & { __scopePasswordToggleField?: Scope };\n\ninterface PasswordToggleFieldProps {\n id?: string;\n visible?: boolean;\n defaultVisible?: boolean;\n onVisibilityChange?: (visible: boolean) => void;\n children?: React.ReactNode;\n}\n\nconst INITIAL_FOCUS_STATE: InternalFocusState = {\n clickTriggered: false,\n selectionStart: null,\n selectionEnd: null,\n};\n\nconst PasswordToggleField: React.FC<PasswordToggleFieldProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldProps>) => {\n const baseId = useId(props.id);\n const defaultInputId = `${baseId}-input`;\n const [inputIdState, setInputIdState] = React.useState<null | string>(defaultInputId);\n const inputId = inputIdState ?? defaultInputId;\n const syncInputId = React.useCallback(\n (providedId: string | number | undefined) =>\n setInputIdState(providedId != null ? String(providedId) : null),\n [],\n );\n\n const { visible: visibleProp, defaultVisible, children } = props;\n\n let onVisibilityChange = props.onVisibilityChange;\n let shouldWarn = false;\n if (\n !onVisibilityChange &&\n 'onVisiblityChange' in props &&\n typeof props.onVisiblityChange === 'function'\n ) {\n shouldWarn = true;\n onVisibilityChange = props.onVisiblityChange as (visible: boolean) => void;\n } else {\n onVisibilityChange = props.onVisibilityChange;\n }\n\n if (IS_DEVELOPMENT) {\n // oxlint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (shouldWarn) {\n console.warn(\n 'PasswordToggleField: The misspelled `onVisiblityChange` prop has been removed. Please use `onVisibilityChange` instead.',\n );\n }\n }, [shouldWarn]);\n }\n\n const [visible = false, setVisible] = useControllableState({\n caller: PASSWORD_TOGGLE_FIELD_NAME,\n prop: visibleProp,\n defaultProp: defaultVisible ?? false,\n onChange: onVisibilityChange,\n });\n\n const inputRef = React.useRef<HTMLInputElement | null>(null);\n const focusState = React.useRef<InternalFocusState>(INITIAL_FOCUS_STATE);\n\n return (\n <PasswordToggleFieldProvider\n scope={__scopePasswordToggleField}\n inputId={inputId}\n inputRef={inputRef}\n setVisible={setVisible}\n syncInputId={syncInputId}\n visible={visible}\n focusState={focusState}\n >\n {children}\n </PasswordToggleFieldProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_INPUT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Input';\n\ntype PrimitiveInputProps = PrimitivePropsWithRef<'input'>;\n\ninterface PasswordToggleFieldOwnProps {\n autoComplete?: 'current-password' | 'new-password';\n}\n\ninterface PasswordToggleFieldInputProps\n extends\n PasswordToggleFieldOwnProps,\n Omit<PrimitiveInputProps, keyof PasswordToggleFieldOwnProps | 'type'> {\n autoComplete?: 'current-password' | 'new-password';\n}\n\nconst PasswordToggleFieldInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n PasswordToggleFieldInputProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldInput(\n {\n __scopePasswordToggleField,\n autoComplete = 'current-password',\n autoCapitalize = 'off',\n spellCheck = false,\n id: idProp,\n ...props\n }: ScopedProps<PasswordToggleFieldInputProps>,\n forwardedRef,\n ) {\n const { visible, inputRef, inputId, syncInputId, setVisible, focusState } =\n usePasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_INPUT_NAME, __scopePasswordToggleField);\n\n React.useEffect(() => {\n syncInputId(idProp);\n }, [idProp, syncInputId]);\n\n // We want to reset the visibility to `false` to revert the input to\n // `type=\"password\"` when:\n // - The form is reset (for consistency with other form controls)\n // - The form is submitted (to prevent the browser from remembering the\n // input's value.\n //\n // See \"Keeping things secure\":\n // https://technology.blog.gov.uk/2021/04/19/simple-things-are-complicated-making-a-show-password-option/)\n const _setVisible = useEffectEvent(setVisible);\n React.useEffect(() => {\n const inputElement = inputRef.current;\n const form = inputElement?.form;\n if (!form) {\n return;\n }\n\n const controller = new AbortController();\n form.addEventListener(\n 'reset',\n (event) => {\n if (!event.defaultPrevented) {\n _setVisible(false);\n }\n },\n { signal: controller.signal },\n );\n form.addEventListener(\n 'submit',\n () => {\n // always reset the visibility on submit regardless of whether the\n // default action is prevented\n _setVisible(false);\n },\n { signal: controller.signal },\n );\n return () => {\n controller.abort();\n };\n }, [inputRef]);\n\n return (\n <Primitive.input\n {...props}\n id={idProp ?? inputId}\n autoCapitalize={autoCapitalize}\n autoComplete={autoComplete}\n ref={useComposedRefs(forwardedRef, inputRef)}\n spellCheck={spellCheck}\n type={visible ? 'text' : 'password'}\n onBlur={composeEventHandlers(props.onBlur, (event) => {\n // get the cursor position\n const { selectionStart, selectionEnd } = event.currentTarget;\n focusState.current.selectionStart = selectionStart;\n focusState.current.selectionEnd = selectionEnd;\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldToggle\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_TOGGLE_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Toggle';\n\ntype PrimitiveButtonProps = PrimitivePropsWithRef<'button'>;\n\ninterface PasswordToggleFieldToggleProps extends Omit<PrimitiveButtonProps, 'type'> {}\n\nconst PasswordToggleFieldToggle = /* @__PURE__ */ React.forwardRef<\n HTMLButtonElement,\n PasswordToggleFieldToggleProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldToggle(\n {\n __scopePasswordToggleField,\n onClick,\n onPointerDown,\n onPointerCancel,\n onPointerUp,\n onFocus,\n children,\n 'aria-label': ariaLabelProp,\n 'aria-controls': ariaControls,\n 'aria-hidden': ariaHidden,\n tabIndex,\n ...props\n }: ScopedProps<PasswordToggleFieldToggleProps>,\n forwardedRef,\n ) {\n const { setVisible, visible, inputRef, inputId, focusState } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_TOGGLE_NAME,\n __scopePasswordToggleField,\n );\n const [internalAriaLabel, setInternalAriaLabel] = React.useState<string | undefined>(undefined);\n const elementRef = React.useRef<HTMLButtonElement>(null);\n const ref = useComposedRefs(forwardedRef, elementRef);\n const isHydrated = useIsHydrated();\n\n React.useEffect(() => {\n const element = elementRef.current;\n if (!element || ariaLabelProp) {\n setInternalAriaLabel(undefined);\n return;\n }\n\n const DEFAULT_ARIA_LABEL = visible ? 'Hide password' : 'Show password';\n\n function checkForInnerTextLabel(textContent: string | undefined | null) {\n const text = textContent ? textContent : undefined;\n // If the element has inner text, no need to force an aria-label.\n setInternalAriaLabel(text ? undefined : DEFAULT_ARIA_LABEL);\n }\n\n checkForInnerTextLabel(element.textContent);\n\n const observer = new MutationObserver((entries) => {\n let textContent: string | undefined;\n for (const entry of entries) {\n if (entry.type === 'characterData') {\n if (element.textContent) {\n textContent = element.textContent;\n }\n }\n }\n checkForInnerTextLabel(textContent);\n });\n observer.observe(element, { characterData: true, subtree: true });\n return () => {\n observer.disconnect();\n };\n }, [visible, ariaLabelProp]);\n\n const ariaLabel = ariaLabelProp || internalAriaLabel;\n\n // Before hydration the button will not work, but we want to render it\n // regardless to prevent potential layout shift. Hide it from assistive tech\n // by default. Post-hydration it will be visible, focusable and associated\n // with the input via aria-controls.\n if (!isHydrated) {\n ariaHidden ??= true;\n tabIndex ??= -1;\n } else {\n ariaControls ??= inputId;\n }\n\n React.useEffect(() => {\n let cleanup = () => {};\n const ownerWindow = elementRef.current?.ownerDocument?.defaultView || window;\n const reset = () => (focusState.current.clickTriggered = false);\n const handlePointerUp = () => (cleanup = requestIdleCallback(ownerWindow, reset));\n ownerWindow.addEventListener('pointerup', handlePointerUp);\n return () => {\n cleanup();\n ownerWindow.removeEventListener('pointerup', handlePointerUp);\n };\n }, [focusState]);\n\n return (\n <Primitive.button\n aria-controls={ariaControls}\n aria-hidden={ariaHidden}\n aria-label={ariaLabel}\n ref={ref}\n id={inputId}\n {...props}\n onPointerDown={composeEventHandlers(onPointerDown, () => {\n focusState.current.clickTriggered = true;\n })}\n onPointerCancel={(event) => {\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref on cancellation, regardless of whether the user has\n // called preventDefault on the event\n onPointerCancel?.(event);\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref after click, regardless of whether the user has\n // called preventDefault on the event\n onClick={(event) => {\n onClick?.(event);\n if (event.defaultPrevented) {\n focusState.current = INITIAL_FOCUS_STATE;\n return;\n }\n\n flushSync(() => {\n setVisible((s) => !s);\n });\n if (focusState.current.clickTriggered) {\n const input = inputRef.current;\n if (input) {\n const { selectionStart, selectionEnd } = focusState.current;\n input.focus();\n if (selectionStart !== null || selectionEnd !== null) {\n // wait a tick so that focus has settled, then restore select position\n requestAnimationFrame(() => {\n // make sure the input still has focus (developer may have\n // programatically moved focus elsewhere)\n if (input.ownerDocument.activeElement === input) {\n input.selectionStart = selectionStart;\n input.selectionEnd = selectionEnd;\n }\n });\n }\n }\n }\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n onPointerUp={(event) => {\n onPointerUp?.(event);\n // if click handler hasn't been called at this point, it may have been\n // intercepted, in which case we still want to reset our internal\n // state\n setTimeout(() => {\n focusState.current = INITIAL_FOCUS_STATE;\n }, 50);\n }}\n type=\"button\"\n >\n {children}\n </Primitive.button>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldSlot\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_SLOT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Slot';\n\ninterface PasswordToggleFieldSlotDeclarativeProps {\n visible: React.ReactNode;\n hidden: React.ReactNode;\n}\n\ninterface PasswordToggleFieldSlotRenderProps {\n render: (args: { visible: boolean }) => React.ReactElement;\n}\n\ntype PasswordToggleFieldSlotProps =\n | PasswordToggleFieldSlotDeclarativeProps\n | PasswordToggleFieldSlotRenderProps;\n\nconst PasswordToggleFieldSlot: React.FC<PasswordToggleFieldSlotProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldSlotProps>) => {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_SLOT_NAME,\n __scopePasswordToggleField,\n );\n\n return 'render' in props\n ? //\n props.render({ visible })\n : visible\n ? props.visible\n : props.hidden;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldIcon\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_ICON_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Icon';\n\ntype PrimitiveSvgProps = PrimitivePropsWithRef<'svg'>;\n\ninterface PasswordToggleFieldIconProps extends Omit<PrimitiveSvgProps, 'children'> {\n visible: React.ReactElement;\n hidden: React.ReactElement;\n}\n\nconst PasswordToggleFieldIcon = /* @__PURE__ */ React.forwardRef<\n SVGSVGElement,\n PasswordToggleFieldIconProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldIcon(\n {\n __scopePasswordToggleField,\n // @ts-expect-error\n children,\n ...props\n }: ScopedProps<PasswordToggleFieldIconProps>,\n forwardedRef,\n ) {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_ICON_NAME,\n __scopePasswordToggleField,\n );\n const { visible: visibleIcon, hidden: hiddenIcon, ...domProps } = props;\n return (\n <Primitive.svg {...domProps} ref={forwardedRef} aria-hidden asChild>\n {visible ? visibleIcon : hiddenIcon}\n </Primitive.svg>\n );\n },\n);\n\nexport {\n PasswordToggleField,\n PasswordToggleFieldInput,\n PasswordToggleFieldToggle,\n PasswordToggleFieldSlot,\n PasswordToggleFieldIcon,\n //\n PasswordToggleField as Root,\n PasswordToggleFieldInput as Input,\n PasswordToggleFieldToggle as Toggle,\n PasswordToggleFieldSlot as Slot,\n PasswordToggleFieldIcon as Icon,\n};\nexport type {\n PasswordToggleFieldProps,\n PasswordToggleFieldInputProps,\n PasswordToggleFieldToggleProps,\n PasswordToggleFieldIconProps,\n PasswordToggleFieldSlotProps,\n};\n\nfunction requestIdleCallback(\n window: Window,\n callback: IdleRequestCallback,\n options?: IdleRequestOptions,\n): () => void {\n if ((window as any).requestIdleCallback) {\n const id = window.requestIdleCallback(callback, options);\n return () => {\n window.cancelIdleCallback(id);\n };\n }\n const start = Date.now();\n const id = window.setTimeout(() => {\n const timeRemaining = () => Math.max(0, 50 - (Date.now() - start));\n callback({ didTimeout: false, timeRemaining });\n }, 1);\n return () => {\n window.clearTimeout(id);\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,uBAA0B;AAC1B,4BAA+B;AAC/B,uBAAqC;AACrC,0CAAqC;AACrC,6BAAsD;AACtD,gCAAgC;AAChC,sBAAsB;AACtB,mCAA8B;AAC9B,oCAA+B;AAE/B,2BAAmC;AAkG/B;AAhGJ,IAAM,6BAA6B;AAqBnC,IAAM,CAAC,gCAAgC,QAAI,yCAAmB,0BAA0B;AACxF,IAAM,CAAC,6BAA6B,6BAA6B,IAC/D,iCAAkE,0BAA0B;AAgB9F,IAAM,sBAA0C;AAAA,EAC9C,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,cAAc;AAChB;AAEA,IAAM,sBAA0D,wBAAC;AAAA,EAC/D;AAAA,EACA,GAAG;AACL,MAA6C;AAC3C,QAAM,aAAS,uBAAM,MAAM,EAAE;AAC7B,QAAM,iBAAiB,GAAG,MAAM;AAChC,QAAM,CAAC,cAAc,eAAe,IAAU,eAAwB,cAAc;AACpF,QAAM,UAAU,gBAAgB;AAChC,QAAM,cAAoB;AAAA,IACxB,CAAC,eACC,gBAAgB,cAAc,OAAO,OAAO,UAAU,IAAI,IAAI;AAAA,IAChE,CAAC;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s
CHANGED
|
@@ -16,10 +16,6 @@ import { useEffectEvent } from "@radix-ui/react-use-effect-event";
|
|
|
16
16
|
import { createContextScope } from "@radix-ui/react-context";
|
|
17
17
|
import { jsx } from "react/jsx-runtime";
|
|
18
18
|
var PASSWORD_TOGGLE_FIELD_NAME = "PasswordToggleField";
|
|
19
|
-
var AutoComplete = {
|
|
20
|
-
CurrentPassword: "current-password",
|
|
21
|
-
NewPassword: "new-password"
|
|
22
|
-
};
|
|
23
19
|
var [createPasswordToggleFieldContext] = createContextScope(PASSWORD_TOGGLE_FIELD_NAME);
|
|
24
20
|
var [PasswordToggleFieldProvider, usePasswordToggleFieldContext] = createPasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_NAME);
|
|
25
21
|
var INITIAL_FOCUS_STATE = {
|
|
@@ -84,7 +80,7 @@ var PasswordToggleFieldInput = /* @__PURE__ */ React.forwardRef(
|
|
|
84
80
|
// blank line to reduce diff noise
|
|
85
81
|
/* @__PURE__ */ __name(function PasswordToggleFieldInput2({
|
|
86
82
|
__scopePasswordToggleField,
|
|
87
|
-
autoComplete =
|
|
83
|
+
autoComplete = "current-password",
|
|
88
84
|
autoCapitalize = "off",
|
|
89
85
|
spellCheck = false,
|
|
90
86
|
id: idProp,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/password-toggle-field.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nimport { flushSync } from 'react-dom';\nimport { IS_DEVELOPMENT } from '@radix-ui/primitive/is-development';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { Primitive, type PrimitivePropsWithRef } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useId } from '@radix-ui/react-id';\nimport { useIsHydrated } from '@radix-ui/react-use-is-hydrated';\nimport { useEffectEvent } from '@radix-ui/react-use-effect-event';\nimport type { Scope } from '@radix-ui/react-context';\nimport { createContextScope } from '@radix-ui/react-context';\n\nconst PASSWORD_TOGGLE_FIELD_NAME = 'PasswordToggleField';\n\nconst AutoComplete = {\n CurrentPassword: 'current-password',\n NewPassword: 'new-password',\n} as const;\n\ntype AutoComplete = (typeof AutoComplete)[keyof typeof AutoComplete];\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldProvider\n * -----------------------------------------------------------------------------------------------*/\n\ntype InternalFocusState = {\n clickTriggered: boolean;\n selectionStart: number | null;\n selectionEnd: number | null;\n};\n\ninterface PasswordToggleFieldContextValue {\n inputId: string;\n inputRef: React.RefObject<HTMLInputElement | null>;\n visible: boolean;\n setVisible: React.Dispatch<React.SetStateAction<boolean>>;\n syncInputId: (providedId: string | number | undefined) => void;\n focusState: React.RefObject<InternalFocusState>;\n}\n\nconst [createPasswordToggleFieldContext] = createContextScope(PASSWORD_TOGGLE_FIELD_NAME);\nconst [PasswordToggleFieldProvider, usePasswordToggleFieldContext] =\n createPasswordToggleFieldContext<PasswordToggleFieldContextValue>(PASSWORD_TOGGLE_FIELD_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleField\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopedProps<P> = P & { __scopePasswordToggleField?: Scope };\n\ninterface PasswordToggleFieldProps {\n id?: string;\n visible?: boolean;\n defaultVisible?: boolean;\n onVisibilityChange?: (visible: boolean) => void;\n children?: React.ReactNode;\n}\n\nconst INITIAL_FOCUS_STATE: InternalFocusState = {\n clickTriggered: false,\n selectionStart: null,\n selectionEnd: null,\n};\n\nconst PasswordToggleField: React.FC<PasswordToggleFieldProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldProps>) => {\n const baseId = useId(props.id);\n const defaultInputId = `${baseId}-input`;\n const [inputIdState, setInputIdState] = React.useState<null | string>(defaultInputId);\n const inputId = inputIdState ?? defaultInputId;\n const syncInputId = React.useCallback(\n (providedId: string | number | undefined) =>\n setInputIdState(providedId != null ? String(providedId) : null),\n [],\n );\n\n const { visible: visibleProp, defaultVisible, children } = props;\n\n let onVisibilityChange = props.onVisibilityChange;\n let shouldWarn = false;\n if (\n !onVisibilityChange &&\n 'onVisiblityChange' in props &&\n typeof props.onVisiblityChange === 'function'\n ) {\n shouldWarn = true;\n onVisibilityChange = props.onVisiblityChange as (visible: boolean) => void;\n } else {\n onVisibilityChange = props.onVisibilityChange;\n }\n\n if (IS_DEVELOPMENT) {\n // oxlint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (shouldWarn) {\n console.warn(\n 'PasswordToggleField: The misspelled `onVisiblityChange` prop has been removed. Please use `onVisibilityChange` instead.',\n );\n }\n }, [shouldWarn]);\n }\n\n const [visible = false, setVisible] = useControllableState({\n caller: PASSWORD_TOGGLE_FIELD_NAME,\n prop: visibleProp,\n defaultProp: defaultVisible ?? false,\n onChange: onVisibilityChange,\n });\n\n const inputRef = React.useRef<HTMLInputElement | null>(null);\n const focusState = React.useRef<InternalFocusState>(INITIAL_FOCUS_STATE);\n\n return (\n <PasswordToggleFieldProvider\n scope={__scopePasswordToggleField}\n inputId={inputId}\n inputRef={inputRef}\n setVisible={setVisible}\n syncInputId={syncInputId}\n visible={visible}\n focusState={focusState}\n >\n {children}\n </PasswordToggleFieldProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_INPUT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Input';\n\ntype PrimitiveInputProps = PrimitivePropsWithRef<'input'>;\n\ninterface PasswordToggleFieldOwnProps {\n autoComplete?: AutoComplete;\n}\n\ninterface PasswordToggleFieldInputProps\n extends\n PasswordToggleFieldOwnProps,\n Omit<PrimitiveInputProps, keyof PasswordToggleFieldOwnProps | 'type'> {\n autoComplete?: AutoComplete;\n}\n\nconst PasswordToggleFieldInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n PasswordToggleFieldInputProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldInput(\n {\n __scopePasswordToggleField,\n autoComplete = AutoComplete.CurrentPassword,\n autoCapitalize = 'off',\n spellCheck = false,\n id: idProp,\n ...props\n }: ScopedProps<PasswordToggleFieldInputProps>,\n forwardedRef,\n ) {\n const { visible, inputRef, inputId, syncInputId, setVisible, focusState } =\n usePasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_INPUT_NAME, __scopePasswordToggleField);\n\n React.useEffect(() => {\n syncInputId(idProp);\n }, [idProp, syncInputId]);\n\n // We want to reset the visibility to `false` to revert the input to\n // `type=\"password\"` when:\n // - The form is reset (for consistency with other form controls)\n // - The form is submitted (to prevent the browser from remembering the\n // input's value.\n //\n // See \"Keeping things secure\":\n // https://technology.blog.gov.uk/2021/04/19/simple-things-are-complicated-making-a-show-password-option/)\n const _setVisible = useEffectEvent(setVisible);\n React.useEffect(() => {\n const inputElement = inputRef.current;\n const form = inputElement?.form;\n if (!form) {\n return;\n }\n\n const controller = new AbortController();\n form.addEventListener(\n 'reset',\n (event) => {\n if (!event.defaultPrevented) {\n _setVisible(false);\n }\n },\n { signal: controller.signal },\n );\n form.addEventListener(\n 'submit',\n () => {\n // always reset the visibility on submit regardless of whether the\n // default action is prevented\n _setVisible(false);\n },\n { signal: controller.signal },\n );\n return () => {\n controller.abort();\n };\n }, [inputRef]);\n\n return (\n <Primitive.input\n {...props}\n id={idProp ?? inputId}\n autoCapitalize={autoCapitalize}\n autoComplete={autoComplete}\n ref={useComposedRefs(forwardedRef, inputRef)}\n spellCheck={spellCheck}\n type={visible ? 'text' : 'password'}\n onBlur={composeEventHandlers(props.onBlur, (event) => {\n // get the cursor position\n const { selectionStart, selectionEnd } = event.currentTarget;\n focusState.current.selectionStart = selectionStart;\n focusState.current.selectionEnd = selectionEnd;\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldToggle\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_TOGGLE_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Toggle';\n\ntype PrimitiveButtonProps = PrimitivePropsWithRef<'button'>;\n\ninterface PasswordToggleFieldToggleProps extends Omit<PrimitiveButtonProps, 'type'> {}\n\nconst PasswordToggleFieldToggle = /* @__PURE__ */ React.forwardRef<\n HTMLButtonElement,\n PasswordToggleFieldToggleProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldToggle(\n {\n __scopePasswordToggleField,\n onClick,\n onPointerDown,\n onPointerCancel,\n onPointerUp,\n onFocus,\n children,\n 'aria-label': ariaLabelProp,\n 'aria-controls': ariaControls,\n 'aria-hidden': ariaHidden,\n tabIndex,\n ...props\n }: ScopedProps<PasswordToggleFieldToggleProps>,\n forwardedRef,\n ) {\n const { setVisible, visible, inputRef, inputId, focusState } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_TOGGLE_NAME,\n __scopePasswordToggleField,\n );\n const [internalAriaLabel, setInternalAriaLabel] = React.useState<string | undefined>(undefined);\n const elementRef = React.useRef<HTMLButtonElement>(null);\n const ref = useComposedRefs(forwardedRef, elementRef);\n const isHydrated = useIsHydrated();\n\n React.useEffect(() => {\n const element = elementRef.current;\n if (!element || ariaLabelProp) {\n setInternalAriaLabel(undefined);\n return;\n }\n\n const DEFAULT_ARIA_LABEL = visible ? 'Hide password' : 'Show password';\n\n function checkForInnerTextLabel(textContent: string | undefined | null) {\n const text = textContent ? textContent : undefined;\n // If the element has inner text, no need to force an aria-label.\n setInternalAriaLabel(text ? undefined : DEFAULT_ARIA_LABEL);\n }\n\n checkForInnerTextLabel(element.textContent);\n\n const observer = new MutationObserver((entries) => {\n let textContent: string | undefined;\n for (const entry of entries) {\n if (entry.type === 'characterData') {\n if (element.textContent) {\n textContent = element.textContent;\n }\n }\n }\n checkForInnerTextLabel(textContent);\n });\n observer.observe(element, { characterData: true, subtree: true });\n return () => {\n observer.disconnect();\n };\n }, [visible, ariaLabelProp]);\n\n const ariaLabel = ariaLabelProp || internalAriaLabel;\n\n // Before hydration the button will not work, but we want to render it\n // regardless to prevent potential layout shift. Hide it from assistive tech\n // by default. Post-hydration it will be visible, focusable and associated\n // with the input via aria-controls.\n if (!isHydrated) {\n ariaHidden ??= true;\n tabIndex ??= -1;\n } else {\n ariaControls ??= inputId;\n }\n\n React.useEffect(() => {\n let cleanup = () => {};\n const ownerWindow = elementRef.current?.ownerDocument?.defaultView || window;\n const reset = () => (focusState.current.clickTriggered = false);\n const handlePointerUp = () => (cleanup = requestIdleCallback(ownerWindow, reset));\n ownerWindow.addEventListener('pointerup', handlePointerUp);\n return () => {\n cleanup();\n ownerWindow.removeEventListener('pointerup', handlePointerUp);\n };\n }, [focusState]);\n\n return (\n <Primitive.button\n aria-controls={ariaControls}\n aria-hidden={ariaHidden}\n aria-label={ariaLabel}\n ref={ref}\n id={inputId}\n {...props}\n onPointerDown={composeEventHandlers(onPointerDown, () => {\n focusState.current.clickTriggered = true;\n })}\n onPointerCancel={(event) => {\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref on cancellation, regardless of whether the user has\n // called preventDefault on the event\n onPointerCancel?.(event);\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref after click, regardless of whether the user has\n // called preventDefault on the event\n onClick={(event) => {\n onClick?.(event);\n if (event.defaultPrevented) {\n focusState.current = INITIAL_FOCUS_STATE;\n return;\n }\n\n flushSync(() => {\n setVisible((s) => !s);\n });\n if (focusState.current.clickTriggered) {\n const input = inputRef.current;\n if (input) {\n const { selectionStart, selectionEnd } = focusState.current;\n input.focus();\n if (selectionStart !== null || selectionEnd !== null) {\n // wait a tick so that focus has settled, then restore select position\n requestAnimationFrame(() => {\n // make sure the input still has focus (developer may have\n // programatically moved focus elsewhere)\n if (input.ownerDocument.activeElement === input) {\n input.selectionStart = selectionStart;\n input.selectionEnd = selectionEnd;\n }\n });\n }\n }\n }\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n onPointerUp={(event) => {\n onPointerUp?.(event);\n // if click handler hasn't been called at this point, it may have been\n // intercepted, in which case we still want to reset our internal\n // state\n setTimeout(() => {\n focusState.current = INITIAL_FOCUS_STATE;\n }, 50);\n }}\n type=\"button\"\n >\n {children}\n </Primitive.button>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldSlot\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_SLOT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Slot';\n\ninterface PasswordToggleFieldSlotDeclarativeProps {\n visible: React.ReactNode;\n hidden: React.ReactNode;\n}\n\ninterface PasswordToggleFieldSlotRenderProps {\n render: (args: { visible: boolean }) => React.ReactElement;\n}\n\ntype PasswordToggleFieldSlotProps =\n | PasswordToggleFieldSlotDeclarativeProps\n | PasswordToggleFieldSlotRenderProps;\n\nconst PasswordToggleFieldSlot: React.FC<PasswordToggleFieldSlotProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldSlotProps>) => {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_SLOT_NAME,\n __scopePasswordToggleField,\n );\n\n return 'render' in props\n ? //\n props.render({ visible })\n : visible\n ? props.visible\n : props.hidden;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldIcon\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_ICON_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Icon';\n\ntype PrimitiveSvgProps = PrimitivePropsWithRef<'svg'>;\n\ninterface PasswordToggleFieldIconProps extends Omit<PrimitiveSvgProps, 'children'> {\n visible: React.ReactElement;\n hidden: React.ReactElement;\n}\n\nconst PasswordToggleFieldIcon = /* @__PURE__ */ React.forwardRef<\n SVGSVGElement,\n PasswordToggleFieldIconProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldIcon(\n {\n __scopePasswordToggleField,\n // @ts-expect-error\n children,\n ...props\n }: ScopedProps<PasswordToggleFieldIconProps>,\n forwardedRef,\n ) {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_ICON_NAME,\n __scopePasswordToggleField,\n );\n const { visible: visibleIcon, hidden: hiddenIcon, ...domProps } = props;\n return (\n <Primitive.svg {...domProps} ref={forwardedRef} aria-hidden asChild>\n {visible ? visibleIcon : hiddenIcon}\n </Primitive.svg>\n );\n },\n);\n\nexport {\n PasswordToggleField,\n PasswordToggleFieldInput,\n PasswordToggleFieldToggle,\n PasswordToggleFieldSlot,\n PasswordToggleFieldIcon,\n //\n PasswordToggleField as Root,\n PasswordToggleFieldInput as Input,\n PasswordToggleFieldToggle as Toggle,\n PasswordToggleFieldSlot as Slot,\n PasswordToggleFieldIcon as Icon,\n};\nexport type {\n PasswordToggleFieldProps,\n PasswordToggleFieldInputProps,\n PasswordToggleFieldToggleProps,\n PasswordToggleFieldIconProps,\n PasswordToggleFieldSlotProps,\n};\n\nfunction requestIdleCallback(\n window: Window,\n callback: IdleRequestCallback,\n options?: IdleRequestOptions,\n): () => void {\n if ((window as any).requestIdleCallback) {\n const id = window.requestIdleCallback(callback, options);\n return () => {\n window.cancelIdleCallback(id);\n };\n }\n const start = Date.now();\n const id = window.setTimeout(() => {\n const timeRemaining = () => Math.max(0, 50 - (Date.now() - start));\n callback({ didTimeout: false, timeRemaining });\n }, 1);\n return () => {\n window.clearTimeout(id);\n };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;AAAA,YAAY,WAAW;AACvB,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AACrC,SAAS,4BAA4B;AACrC,SAAS,iBAA6C;AACtD,SAAS,uBAAuB;AAChC,SAAS,aAAa;AACtB,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAE/B,SAAS,0BAA0B;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nimport { flushSync } from 'react-dom';\nimport { IS_DEVELOPMENT } from '@radix-ui/primitive/is-development';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { Primitive, type PrimitivePropsWithRef } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useId } from '@radix-ui/react-id';\nimport { useIsHydrated } from '@radix-ui/react-use-is-hydrated';\nimport { useEffectEvent } from '@radix-ui/react-use-effect-event';\nimport type { Scope } from '@radix-ui/react-context';\nimport { createContextScope } from '@radix-ui/react-context';\n\nconst PASSWORD_TOGGLE_FIELD_NAME = 'PasswordToggleField';\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldProvider\n * -----------------------------------------------------------------------------------------------*/\n\ntype InternalFocusState = {\n clickTriggered: boolean;\n selectionStart: number | null;\n selectionEnd: number | null;\n};\n\ninterface PasswordToggleFieldContextValue {\n inputId: string;\n inputRef: React.RefObject<HTMLInputElement | null>;\n visible: boolean;\n setVisible: React.Dispatch<React.SetStateAction<boolean>>;\n syncInputId: (providedId: string | number | undefined) => void;\n focusState: React.RefObject<InternalFocusState>;\n}\n\nconst [createPasswordToggleFieldContext] = createContextScope(PASSWORD_TOGGLE_FIELD_NAME);\nconst [PasswordToggleFieldProvider, usePasswordToggleFieldContext] =\n createPasswordToggleFieldContext<PasswordToggleFieldContextValue>(PASSWORD_TOGGLE_FIELD_NAME);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleField\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopedProps<P> = P & { __scopePasswordToggleField?: Scope };\n\ninterface PasswordToggleFieldProps {\n id?: string;\n visible?: boolean;\n defaultVisible?: boolean;\n onVisibilityChange?: (visible: boolean) => void;\n children?: React.ReactNode;\n}\n\nconst INITIAL_FOCUS_STATE: InternalFocusState = {\n clickTriggered: false,\n selectionStart: null,\n selectionEnd: null,\n};\n\nconst PasswordToggleField: React.FC<PasswordToggleFieldProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldProps>) => {\n const baseId = useId(props.id);\n const defaultInputId = `${baseId}-input`;\n const [inputIdState, setInputIdState] = React.useState<null | string>(defaultInputId);\n const inputId = inputIdState ?? defaultInputId;\n const syncInputId = React.useCallback(\n (providedId: string | number | undefined) =>\n setInputIdState(providedId != null ? String(providedId) : null),\n [],\n );\n\n const { visible: visibleProp, defaultVisible, children } = props;\n\n let onVisibilityChange = props.onVisibilityChange;\n let shouldWarn = false;\n if (\n !onVisibilityChange &&\n 'onVisiblityChange' in props &&\n typeof props.onVisiblityChange === 'function'\n ) {\n shouldWarn = true;\n onVisibilityChange = props.onVisiblityChange as (visible: boolean) => void;\n } else {\n onVisibilityChange = props.onVisibilityChange;\n }\n\n if (IS_DEVELOPMENT) {\n // oxlint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (shouldWarn) {\n console.warn(\n 'PasswordToggleField: The misspelled `onVisiblityChange` prop has been removed. Please use `onVisibilityChange` instead.',\n );\n }\n }, [shouldWarn]);\n }\n\n const [visible = false, setVisible] = useControllableState({\n caller: PASSWORD_TOGGLE_FIELD_NAME,\n prop: visibleProp,\n defaultProp: defaultVisible ?? false,\n onChange: onVisibilityChange,\n });\n\n const inputRef = React.useRef<HTMLInputElement | null>(null);\n const focusState = React.useRef<InternalFocusState>(INITIAL_FOCUS_STATE);\n\n return (\n <PasswordToggleFieldProvider\n scope={__scopePasswordToggleField}\n inputId={inputId}\n inputRef={inputRef}\n setVisible={setVisible}\n syncInputId={syncInputId}\n visible={visible}\n focusState={focusState}\n >\n {children}\n </PasswordToggleFieldProvider>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldInput\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_INPUT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Input';\n\ntype PrimitiveInputProps = PrimitivePropsWithRef<'input'>;\n\ninterface PasswordToggleFieldOwnProps {\n autoComplete?: 'current-password' | 'new-password';\n}\n\ninterface PasswordToggleFieldInputProps\n extends\n PasswordToggleFieldOwnProps,\n Omit<PrimitiveInputProps, keyof PasswordToggleFieldOwnProps | 'type'> {\n autoComplete?: 'current-password' | 'new-password';\n}\n\nconst PasswordToggleFieldInput = /* @__PURE__ */ React.forwardRef<\n HTMLInputElement,\n PasswordToggleFieldInputProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldInput(\n {\n __scopePasswordToggleField,\n autoComplete = 'current-password',\n autoCapitalize = 'off',\n spellCheck = false,\n id: idProp,\n ...props\n }: ScopedProps<PasswordToggleFieldInputProps>,\n forwardedRef,\n ) {\n const { visible, inputRef, inputId, syncInputId, setVisible, focusState } =\n usePasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_INPUT_NAME, __scopePasswordToggleField);\n\n React.useEffect(() => {\n syncInputId(idProp);\n }, [idProp, syncInputId]);\n\n // We want to reset the visibility to `false` to revert the input to\n // `type=\"password\"` when:\n // - The form is reset (for consistency with other form controls)\n // - The form is submitted (to prevent the browser from remembering the\n // input's value.\n //\n // See \"Keeping things secure\":\n // https://technology.blog.gov.uk/2021/04/19/simple-things-are-complicated-making-a-show-password-option/)\n const _setVisible = useEffectEvent(setVisible);\n React.useEffect(() => {\n const inputElement = inputRef.current;\n const form = inputElement?.form;\n if (!form) {\n return;\n }\n\n const controller = new AbortController();\n form.addEventListener(\n 'reset',\n (event) => {\n if (!event.defaultPrevented) {\n _setVisible(false);\n }\n },\n { signal: controller.signal },\n );\n form.addEventListener(\n 'submit',\n () => {\n // always reset the visibility on submit regardless of whether the\n // default action is prevented\n _setVisible(false);\n },\n { signal: controller.signal },\n );\n return () => {\n controller.abort();\n };\n }, [inputRef]);\n\n return (\n <Primitive.input\n {...props}\n id={idProp ?? inputId}\n autoCapitalize={autoCapitalize}\n autoComplete={autoComplete}\n ref={useComposedRefs(forwardedRef, inputRef)}\n spellCheck={spellCheck}\n type={visible ? 'text' : 'password'}\n onBlur={composeEventHandlers(props.onBlur, (event) => {\n // get the cursor position\n const { selectionStart, selectionEnd } = event.currentTarget;\n focusState.current.selectionStart = selectionStart;\n focusState.current.selectionEnd = selectionEnd;\n })}\n />\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldToggle\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_TOGGLE_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Toggle';\n\ntype PrimitiveButtonProps = PrimitivePropsWithRef<'button'>;\n\ninterface PasswordToggleFieldToggleProps extends Omit<PrimitiveButtonProps, 'type'> {}\n\nconst PasswordToggleFieldToggle = /* @__PURE__ */ React.forwardRef<\n HTMLButtonElement,\n PasswordToggleFieldToggleProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldToggle(\n {\n __scopePasswordToggleField,\n onClick,\n onPointerDown,\n onPointerCancel,\n onPointerUp,\n onFocus,\n children,\n 'aria-label': ariaLabelProp,\n 'aria-controls': ariaControls,\n 'aria-hidden': ariaHidden,\n tabIndex,\n ...props\n }: ScopedProps<PasswordToggleFieldToggleProps>,\n forwardedRef,\n ) {\n const { setVisible, visible, inputRef, inputId, focusState } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_TOGGLE_NAME,\n __scopePasswordToggleField,\n );\n const [internalAriaLabel, setInternalAriaLabel] = React.useState<string | undefined>(undefined);\n const elementRef = React.useRef<HTMLButtonElement>(null);\n const ref = useComposedRefs(forwardedRef, elementRef);\n const isHydrated = useIsHydrated();\n\n React.useEffect(() => {\n const element = elementRef.current;\n if (!element || ariaLabelProp) {\n setInternalAriaLabel(undefined);\n return;\n }\n\n const DEFAULT_ARIA_LABEL = visible ? 'Hide password' : 'Show password';\n\n function checkForInnerTextLabel(textContent: string | undefined | null) {\n const text = textContent ? textContent : undefined;\n // If the element has inner text, no need to force an aria-label.\n setInternalAriaLabel(text ? undefined : DEFAULT_ARIA_LABEL);\n }\n\n checkForInnerTextLabel(element.textContent);\n\n const observer = new MutationObserver((entries) => {\n let textContent: string | undefined;\n for (const entry of entries) {\n if (entry.type === 'characterData') {\n if (element.textContent) {\n textContent = element.textContent;\n }\n }\n }\n checkForInnerTextLabel(textContent);\n });\n observer.observe(element, { characterData: true, subtree: true });\n return () => {\n observer.disconnect();\n };\n }, [visible, ariaLabelProp]);\n\n const ariaLabel = ariaLabelProp || internalAriaLabel;\n\n // Before hydration the button will not work, but we want to render it\n // regardless to prevent potential layout shift. Hide it from assistive tech\n // by default. Post-hydration it will be visible, focusable and associated\n // with the input via aria-controls.\n if (!isHydrated) {\n ariaHidden ??= true;\n tabIndex ??= -1;\n } else {\n ariaControls ??= inputId;\n }\n\n React.useEffect(() => {\n let cleanup = () => {};\n const ownerWindow = elementRef.current?.ownerDocument?.defaultView || window;\n const reset = () => (focusState.current.clickTriggered = false);\n const handlePointerUp = () => (cleanup = requestIdleCallback(ownerWindow, reset));\n ownerWindow.addEventListener('pointerup', handlePointerUp);\n return () => {\n cleanup();\n ownerWindow.removeEventListener('pointerup', handlePointerUp);\n };\n }, [focusState]);\n\n return (\n <Primitive.button\n aria-controls={ariaControls}\n aria-hidden={ariaHidden}\n aria-label={ariaLabel}\n ref={ref}\n id={inputId}\n {...props}\n onPointerDown={composeEventHandlers(onPointerDown, () => {\n focusState.current.clickTriggered = true;\n })}\n onPointerCancel={(event) => {\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref on cancellation, regardless of whether the user has\n // called preventDefault on the event\n onPointerCancel?.(event);\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n // do not use `composeEventHandlers` here because we always want to\n // reset the ref after click, regardless of whether the user has\n // called preventDefault on the event\n onClick={(event) => {\n onClick?.(event);\n if (event.defaultPrevented) {\n focusState.current = INITIAL_FOCUS_STATE;\n return;\n }\n\n flushSync(() => {\n setVisible((s) => !s);\n });\n if (focusState.current.clickTriggered) {\n const input = inputRef.current;\n if (input) {\n const { selectionStart, selectionEnd } = focusState.current;\n input.focus();\n if (selectionStart !== null || selectionEnd !== null) {\n // wait a tick so that focus has settled, then restore select position\n requestAnimationFrame(() => {\n // make sure the input still has focus (developer may have\n // programatically moved focus elsewhere)\n if (input.ownerDocument.activeElement === input) {\n input.selectionStart = selectionStart;\n input.selectionEnd = selectionEnd;\n }\n });\n }\n }\n }\n focusState.current = INITIAL_FOCUS_STATE;\n }}\n onPointerUp={(event) => {\n onPointerUp?.(event);\n // if click handler hasn't been called at this point, it may have been\n // intercepted, in which case we still want to reset our internal\n // state\n setTimeout(() => {\n focusState.current = INITIAL_FOCUS_STATE;\n }, 50);\n }}\n type=\"button\"\n >\n {children}\n </Primitive.button>\n );\n },\n);\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldSlot\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_SLOT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Slot';\n\ninterface PasswordToggleFieldSlotDeclarativeProps {\n visible: React.ReactNode;\n hidden: React.ReactNode;\n}\n\ninterface PasswordToggleFieldSlotRenderProps {\n render: (args: { visible: boolean }) => React.ReactElement;\n}\n\ntype PasswordToggleFieldSlotProps =\n | PasswordToggleFieldSlotDeclarativeProps\n | PasswordToggleFieldSlotRenderProps;\n\nconst PasswordToggleFieldSlot: React.FC<PasswordToggleFieldSlotProps> = ({\n __scopePasswordToggleField,\n ...props\n}: ScopedProps<PasswordToggleFieldSlotProps>) => {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_SLOT_NAME,\n __scopePasswordToggleField,\n );\n\n return 'render' in props\n ? //\n props.render({ visible })\n : visible\n ? props.visible\n : props.hidden;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * PasswordToggleFieldIcon\n * -----------------------------------------------------------------------------------------------*/\n\nconst PASSWORD_TOGGLE_FIELD_ICON_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Icon';\n\ntype PrimitiveSvgProps = PrimitivePropsWithRef<'svg'>;\n\ninterface PasswordToggleFieldIconProps extends Omit<PrimitiveSvgProps, 'children'> {\n visible: React.ReactElement;\n hidden: React.ReactElement;\n}\n\nconst PasswordToggleFieldIcon = /* @__PURE__ */ React.forwardRef<\n SVGSVGElement,\n PasswordToggleFieldIconProps\n>(\n // blank line to reduce diff noise\n function PasswordToggleFieldIcon(\n {\n __scopePasswordToggleField,\n // @ts-expect-error\n children,\n ...props\n }: ScopedProps<PasswordToggleFieldIconProps>,\n forwardedRef,\n ) {\n const { visible } = usePasswordToggleFieldContext(\n PASSWORD_TOGGLE_FIELD_ICON_NAME,\n __scopePasswordToggleField,\n );\n const { visible: visibleIcon, hidden: hiddenIcon, ...domProps } = props;\n return (\n <Primitive.svg {...domProps} ref={forwardedRef} aria-hidden asChild>\n {visible ? visibleIcon : hiddenIcon}\n </Primitive.svg>\n );\n },\n);\n\nexport {\n PasswordToggleField,\n PasswordToggleFieldInput,\n PasswordToggleFieldToggle,\n PasswordToggleFieldSlot,\n PasswordToggleFieldIcon,\n //\n PasswordToggleField as Root,\n PasswordToggleFieldInput as Input,\n PasswordToggleFieldToggle as Toggle,\n PasswordToggleFieldSlot as Slot,\n PasswordToggleFieldIcon as Icon,\n};\nexport type {\n PasswordToggleFieldProps,\n PasswordToggleFieldInputProps,\n PasswordToggleFieldToggleProps,\n PasswordToggleFieldIconProps,\n PasswordToggleFieldSlotProps,\n};\n\nfunction requestIdleCallback(\n window: Window,\n callback: IdleRequestCallback,\n options?: IdleRequestOptions,\n): () => void {\n if ((window as any).requestIdleCallback) {\n const id = window.requestIdleCallback(callback, options);\n return () => {\n window.cancelIdleCallback(id);\n };\n }\n const start = Date.now();\n const id = window.setTimeout(() => {\n const timeRemaining = () => Math.max(0, 50 - (Date.now() - start));\n callback({ didTimeout: false, timeRemaining });\n }, 1);\n return () => {\n window.clearTimeout(id);\n };\n}\n"],
|
|
5
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AA,IACF;AACA,UAAM,EAAE,SAAS,aAAa,QAAQ,YAAY,GAAG,SAAS,IAAI;AAClE,WACE,oBAAC,UAAU,KAAV,EAAe,GAAG,UAAU,KAAK,cAAc,eAAW,MAAC,SAAO,MAChE,oBAAU,cAAc,YAC3B;AAAA,EAEJ,GAnBA;AAoBF;AAuBA,SAAS,oBACPC,SACA,UACA,SACY;AACZ,MAAKA,QAAe,qBAAqB;AACvC,UAAMC,MAAKD,QAAO,oBAAoB,UAAU,OAAO;AACvD,WAAO,MAAM;AACX,MAAAA,QAAO,mBAAmBC,GAAE;AAAA,IAC9B;AAAA,EACF;AACA,QAAM,QAAQ,KAAK,IAAI;AACvB,QAAM,KAAKD,QAAO,WAAW,MAAM;AACjC,UAAM,gBAAgB,6BAAM,KAAK,IAAI,GAAG,MAAM,KAAK,IAAI,IAAI,MAAM,GAA3C;AACtB,aAAS,EAAE,YAAY,OAAO,cAAc,CAAC;AAAA,EAC/C,GAAG,CAAC;AACJ,SAAO,MAAM;AACX,IAAAA,QAAO,aAAa,EAAE;AAAA,EACxB;AACF;AAnBS;",
|
|
6
6
|
"names": ["PasswordToggleFieldInput", "PasswordToggleFieldToggle", "PasswordToggleFieldIcon", "window", "id"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radix-ui/react-password-toggle-field",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -13,19 +13,19 @@
|
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@radix-ui/primitive": "1.1.7",
|
|
16
|
-
"@radix-ui/react-
|
|
17
|
-
"@radix-ui/react-
|
|
18
|
-
"@radix-ui/react-
|
|
19
|
-
"@radix-ui/react-primitive": "2.1.
|
|
20
|
-
"@radix-ui/react-use-controllable-state": "1.2.
|
|
21
|
-
"@radix-ui/react-use-effect-event": "0.0.
|
|
22
|
-
"@radix-ui/react-use-is-hydrated": "0.1.
|
|
16
|
+
"@radix-ui/react-context": "1.2.2",
|
|
17
|
+
"@radix-ui/react-id": "1.1.4",
|
|
18
|
+
"@radix-ui/react-compose-refs": "1.1.5",
|
|
19
|
+
"@radix-ui/react-primitive": "2.1.10",
|
|
20
|
+
"@radix-ui/react-use-controllable-state": "1.2.6",
|
|
21
|
+
"@radix-ui/react-use-effect-event": "0.0.5",
|
|
22
|
+
"@radix-ui/react-use-is-hydrated": "0.1.3"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/react": "^19.2.
|
|
26
|
-
"@types/react-dom": "^19.2.
|
|
27
|
-
"react": "^19.2.
|
|
28
|
-
"react-dom": "^19.2.
|
|
25
|
+
"@types/react": "^19.2.2",
|
|
26
|
+
"@types/react-dom": "^19.2.2",
|
|
27
|
+
"react": "^19.2.0",
|
|
28
|
+
"react-dom": "^19.2.0",
|
|
29
29
|
"typescript": "^5.9.3",
|
|
30
30
|
"@repo/builder": "0.0.0",
|
|
31
31
|
"@repo/typescript-config": "0.0.0"
|
|
@@ -13,13 +13,6 @@ import { createContextScope } from '@radix-ui/react-context';
|
|
|
13
13
|
|
|
14
14
|
const PASSWORD_TOGGLE_FIELD_NAME = 'PasswordToggleField';
|
|
15
15
|
|
|
16
|
-
const AutoComplete = {
|
|
17
|
-
CurrentPassword: 'current-password',
|
|
18
|
-
NewPassword: 'new-password',
|
|
19
|
-
} as const;
|
|
20
|
-
|
|
21
|
-
type AutoComplete = (typeof AutoComplete)[keyof typeof AutoComplete];
|
|
22
|
-
|
|
23
16
|
/* -------------------------------------------------------------------------------------------------
|
|
24
17
|
* PasswordToggleFieldProvider
|
|
25
18
|
* -----------------------------------------------------------------------------------------------*/
|
|
@@ -137,14 +130,14 @@ const PASSWORD_TOGGLE_FIELD_INPUT_NAME = PASSWORD_TOGGLE_FIELD_NAME + 'Input';
|
|
|
137
130
|
type PrimitiveInputProps = PrimitivePropsWithRef<'input'>;
|
|
138
131
|
|
|
139
132
|
interface PasswordToggleFieldOwnProps {
|
|
140
|
-
autoComplete?:
|
|
133
|
+
autoComplete?: 'current-password' | 'new-password';
|
|
141
134
|
}
|
|
142
135
|
|
|
143
136
|
interface PasswordToggleFieldInputProps
|
|
144
137
|
extends
|
|
145
138
|
PasswordToggleFieldOwnProps,
|
|
146
139
|
Omit<PrimitiveInputProps, keyof PasswordToggleFieldOwnProps | 'type'> {
|
|
147
|
-
autoComplete?:
|
|
140
|
+
autoComplete?: 'current-password' | 'new-password';
|
|
148
141
|
}
|
|
149
142
|
|
|
150
143
|
const PasswordToggleFieldInput = /* @__PURE__ */ React.forwardRef<
|
|
@@ -155,7 +148,7 @@ const PasswordToggleFieldInput = /* @__PURE__ */ React.forwardRef<
|
|
|
155
148
|
function PasswordToggleFieldInput(
|
|
156
149
|
{
|
|
157
150
|
__scopePasswordToggleField,
|
|
158
|
-
autoComplete =
|
|
151
|
+
autoComplete = 'current-password',
|
|
159
152
|
autoCapitalize = 'off',
|
|
160
153
|
spellCheck = false,
|
|
161
154
|
id: idProp,
|