map • Lines: 1{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAkDM,SAAS,0CAAe,QAA4B,CAAC,CAAC;IAC3D,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,8EAA8E;IAC9E,+FAA+F;IAC/F,IAAI,CAAC,YAAY,YAAY,GAAG,CAAA,GAAA,4CAAiB,EAC/C,MAAM,UAAU,EAChB,MAAM,eAAe,IAAI,OACzB,MAAM,QAAQ;IAEhB,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE;IAE9B,SAAS,eAAe,KAAK;QAC3B,IAAI,CAAC,YACH,YAAY;IAEhB;IAEA,SAAS;QACP,IAAI,CAAC,YACH,YAAY,CAAC;IAEjB;IAEA,OAAO;oBACL;QACA,iBAAiB,MAAM,eAAe,IAAI;QAC1C,aAAa;QACb,QAAQ;IACV;AACF","sources":["packages/react-stately/src/toggle/useToggleState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusableProps, InputBase, Validation} from '@react-types/shared';\nimport {ReactNode, useState} from 'react';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface ToggleStateOptions extends InputBase {\n /**\n * Whether the element should be selected (uncontrolled).\n */\n defaultSelected?: boolean;\n /**\n * Whether the element should be selected (controlled).\n */\n isSelected?: boolean;\n /**\n * Handler that is called when the element's selection state changes.\n */\n onChange?: (isSelected: boolean) => void;\n}\n\nexport interface ToggleProps extends ToggleStateOptions, Validation<boolean>, FocusableProps {\n /**\n * The label for the element.\n */\n children?: ReactNode;\n /**\n * The value of the input element, used when submitting an HTML form. See\n * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefvalue).\n */\n value?: string;\n}\n\nexport interface ToggleState {\n /** Whether the toggle is selected. */\n readonly isSelected: boolean;\n\n /** Whether the toggle is selected by default. */\n readonly defaultSelected: boolean;\n\n /** Updates selection state. */\n setSelected(isSelected: boolean): void;\n\n /** Toggle the selection state. */\n toggle(): void;\n}\n\n/**\n * Provides state management for toggle components like checkboxes and switches.\n */\nexport function useToggleState(props: ToggleStateOptions = {}): ToggleState {\n let {isReadOnly} = props;\n\n // have to provide an empty function so useControlledState doesn't throw a fit\n // can't use useControlledState's prop calling because we need the event object from the change\n let [isSelected, setSelected] = useControlledState(\n props.isSelected,\n props.defaultSelected || false,\n props.onChange\n );\n let [initialValue] = useState(isSelected);\n\n function updateSelected(value) {\n if (!isReadOnly) {\n setSelected(value);\n }\n }\n\n function toggleState() {\n if (!isReadOnly) {\n setSelected(!isSelected);\n }\n }\n\n return {\n isSelected,\n defaultSelected: props.defaultSelected ?? initialValue,\n setSelected: updateSelected,\n toggle: toggleState\n };\n}\n"],"names":[],"version":3,"file":"useToggleState.cjs.map"}