@solid-aria/toggle
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -79,2 +79,6 @@ import { InputBase, Validation, FocusableProps, FocusableDOMProps, AriaLabelingProps, AriaValidationProps } from '@solid-aria/types'; | ||
inputProps: Accessor<JSX.InputHTMLAttributes<HTMLInputElement>>; | ||
/** | ||
* State for the toggle element, as returned by `createToggleState`. | ||
*/ | ||
state: ToggleState; | ||
} | ||
@@ -84,7 +88,6 @@ /** | ||
* @param props - Props for the toggle element. | ||
* @param state - State for the toggle element, as returned by `createToggleState`. | ||
* @param inputRef - Ref to the HTML input element. | ||
*/ | ||
declare function createToggle(props: AriaToggleProps, state: ToggleState, inputRef: Accessor<HTMLInputElement | undefined>): ToggleAria; | ||
declare function createToggle(props: AriaToggleProps, inputRef: Accessor<HTMLInputElement | undefined>): ToggleAria; | ||
export { AriaToggleProps, ToggleAria, ToggleState, createToggle, createToggleState }; |
@@ -6,3 +6,32 @@ // src/createToggle.ts | ||
import { createMemo, mergeProps, splitProps } from "solid-js"; | ||
function createToggle(props, state, inputRef) { | ||
// src/createToggleState.ts | ||
import { createControllableBooleanSignal } from "@solid-aria/utils"; | ||
import { access } from "@solid-primitives/utils"; | ||
function createToggleState(props = {}) { | ||
const [isSelected, setSelected] = createControllableBooleanSignal({ | ||
value: () => access(props.isSelected), | ||
defaultValue: () => !!access(props.defaultSelected), | ||
onChange: props.onChange | ||
}); | ||
const updateSelected = (value) => { | ||
if (!access(props.isReadOnly)) { | ||
setSelected(value); | ||
} | ||
}; | ||
const toggleSelected = () => { | ||
if (!access(props.isReadOnly)) { | ||
setSelected(!isSelected()); | ||
} | ||
}; | ||
return { | ||
isSelected, | ||
setSelected: updateSelected, | ||
toggle: toggleSelected | ||
}; | ||
} | ||
// src/createToggle.ts | ||
function createToggle(props, inputRef) { | ||
const state = createToggleState(props); | ||
const defaultProps = { | ||
@@ -46,30 +75,4 @@ isDisabled: false, | ||
}); | ||
return { inputProps }; | ||
return { inputProps, state }; | ||
} | ||
// src/createToggleState.ts | ||
import { createControllableBooleanSignal } from "@solid-aria/utils"; | ||
import { access } from "@solid-primitives/utils"; | ||
function createToggleState(props = {}) { | ||
const [isSelected, setSelected] = createControllableBooleanSignal({ | ||
value: () => access(props.isSelected), | ||
defaultValue: () => !!access(props.defaultSelected), | ||
onChange: props.onChange | ||
}); | ||
const updateSelected = (value) => { | ||
if (!access(props.isReadOnly)) { | ||
setSelected(value); | ||
} | ||
}; | ||
const toggleSelected = () => { | ||
if (!access(props.isReadOnly)) { | ||
setSelected(!isSelected()); | ||
} | ||
}; | ||
return { | ||
isSelected, | ||
setSelected: updateSelected, | ||
toggle: toggleSelected | ||
}; | ||
} | ||
export { | ||
@@ -76,0 +79,0 @@ createToggle, |
{ | ||
"name": "@solid-aria/toggle", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Primitives for building toggle components like checkboxes and switches.", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
13376
267
0