node_modules ignore

This commit is contained in:
oier committed 2025-05-08 23:43:47 +02:00
1 parent e19d52f172
commit 4574544c9f
65041 files changed
+10593536

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
# `react-switch`
## Installation
```sh
$ yarn add @radix-ui/react-switch
# or
$ npm install @radix-ui/react-switch
```
## Usage
View docs [here](https://radix-ui.com/primitives/docs/components/switch).
+20
View File
@@ -0,0 +1,20 @@
import * as React from "react";
import * as Radix from "@radix-ui/react-primitive";
import { Primitive } from "@radix-ui/react-primitive";
export const createSwitchScope: import("@radix-ui/react-context").CreateScope;
type PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;
export interface SwitchProps extends PrimitiveButtonProps {
checked?: boolean;
defaultChecked?: boolean;
required?: boolean;
onCheckedChange?(checked: boolean): void;
}
export const Switch: React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLButtonElement>>;
type PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;
export interface SwitchThumbProps extends PrimitiveSpanProps {
}
export const SwitchThumb: React.ForwardRefExoticComponent<SwitchThumbProps & React.RefAttributes<HTMLSpanElement>>;
export const Root: React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLButtonElement>>;
export const Thumb: React.ForwardRefExoticComponent<SwitchThumbProps & React.RefAttributes<HTMLSpanElement>>;
//# sourceMappingURL=index.d.ts.map
+20
View File
@@ -0,0 +1,20 @@
import * as React from "react";
import * as Radix from "@radix-ui/react-primitive";
import { Primitive } from "@radix-ui/react-primitive";
export const createSwitchScope: import("@radix-ui/react-context").CreateScope;
type PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;
export interface SwitchProps extends PrimitiveButtonProps {
checked?: boolean;
defaultChecked?: boolean;
required?: boolean;
onCheckedChange?(checked: boolean): void;
}
export const Switch: React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLButtonElement>>;
type PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;
export interface SwitchThumbProps extends PrimitiveSpanProps {
}
export const SwitchThumb: React.ForwardRefExoticComponent<SwitchThumbProps & React.RefAttributes<HTMLSpanElement>>;
export const Root: React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLButtonElement>>;
export const Thumb: React.ForwardRefExoticComponent<SwitchThumbProps & React.RefAttributes<HTMLSpanElement>>;
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"mappings":";;;AAmBA,OAAA,wFAAgF,CAAC;AAMjF,4BAA4B,MAAM,wBAAwB,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC;AACpF,4BAAsB,SAAQ,oBAAoB;IAChD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CAC1C;AAED,OAAA,MAAM,6FAkEL,CAAC;AAWF,0BAA0B,MAAM,wBAAwB,CAAC,OAAO,UAAU,IAAI,CAAC,CAAC;AAChF,iCAA2B,SAAQ,kBAAkB;CAAG;AAExD,OAAA,MAAM,qGAaL,CAAC;AAwDF,OAAA,MAAM,2FAAa,CAAC;AACpB,OAAA,MAAM,+FAAmB,CAAC","sources":["packages/react/switch/src/packages/react/switch/src/Switch.tsx","packages/react/switch/src/packages/react/switch/src/index.ts","packages/react/switch/src/index.ts"],"sourcesContent":[null,null,"export {\n createSwitchScope,\n //\n Switch,\n SwitchThumb,\n //\n Root,\n Thumb,\n} from './Switch';\nexport type { SwitchProps, SwitchThumbProps } from './Switch';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
+155
View File
@@ -0,0 +1,155 @@
var $cWV9h$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
var $cWV9h$react = require("react");
var $cWV9h$radixuiprimitive = require("@radix-ui/primitive");
var $cWV9h$radixuireactcomposerefs = require("@radix-ui/react-compose-refs");
var $cWV9h$radixuireactcontext = require("@radix-ui/react-context");
var $cWV9h$radixuireactusecontrollablestate = require("@radix-ui/react-use-controllable-state");
var $cWV9h$radixuireactuseprevious = require("@radix-ui/react-use-previous");
var $cWV9h$radixuireactusesize = require("@radix-ui/react-use-size");
var $cWV9h$radixuireactprimitive = require("@radix-ui/react-primitive");
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
}
$parcel$export(module.exports, "createSwitchScope", () => $4465bdeb0ef4ccd7$export$cf7f5f17f69cbd43);
$parcel$export(module.exports, "Switch", () => $4465bdeb0ef4ccd7$export$b5d5cf8927ab7262);
$parcel$export(module.exports, "SwitchThumb", () => $4465bdeb0ef4ccd7$export$4d07bf653ea69106);
$parcel$export(module.exports, "Root", () => $4465bdeb0ef4ccd7$export$be92b6f5f03c0fe9);
$parcel$export(module.exports, "Thumb", () => $4465bdeb0ef4ccd7$export$6521433ed15a34db);
/* -------------------------------------------------------------------------------------------------
* Switch
* -----------------------------------------------------------------------------------------------*/ const $4465bdeb0ef4ccd7$var$SWITCH_NAME = 'Switch';
const [$4465bdeb0ef4ccd7$var$createSwitchContext, $4465bdeb0ef4ccd7$export$cf7f5f17f69cbd43] = $cWV9h$radixuireactcontext.createContextScope($4465bdeb0ef4ccd7$var$SWITCH_NAME);
const [$4465bdeb0ef4ccd7$var$SwitchProvider, $4465bdeb0ef4ccd7$var$useSwitchContext] = $4465bdeb0ef4ccd7$var$createSwitchContext($4465bdeb0ef4ccd7$var$SWITCH_NAME);
const $4465bdeb0ef4ccd7$export$b5d5cf8927ab7262 = /*#__PURE__*/ $cWV9h$react.forwardRef((props, forwardedRef)=>{
const { __scopeSwitch: __scopeSwitch , name: name , checked: checkedProp , defaultChecked: defaultChecked , required: required , disabled: disabled , value: value = 'on' , onCheckedChange: onCheckedChange , ...switchProps } = props;
const [button, setButton] = $cWV9h$react.useState(null);
const composedRefs = $cWV9h$radixuireactcomposerefs.useComposedRefs(forwardedRef, (node)=>setButton(node)
);
const hasConsumerStoppedPropagationRef = $cWV9h$react.useRef(false); // We set this to true by default so that events bubble to forms without JS (SSR)
const isFormControl = button ? Boolean(button.closest('form')) : true;
const [checked = false, setChecked] = $cWV9h$radixuireactusecontrollablestate.useControllableState({
prop: checkedProp,
defaultProp: defaultChecked,
onChange: onCheckedChange
});
return /*#__PURE__*/ $cWV9h$react.createElement($4465bdeb0ef4ccd7$var$SwitchProvider, {
scope: __scopeSwitch,
checked: checked,
disabled: disabled
}, /*#__PURE__*/ $cWV9h$react.createElement($cWV9h$radixuireactprimitive.Primitive.button, ($parcel$interopDefault($cWV9h$babelruntimehelpersextends))({
type: "button",
role: "switch",
"aria-checked": checked,
"aria-required": required,
"data-state": $4465bdeb0ef4ccd7$var$getState(checked),
"data-disabled": disabled ? '' : undefined,
disabled: disabled,
value: value
}, switchProps, {
ref: composedRefs,
onClick: $cWV9h$radixuiprimitive.composeEventHandlers(props.onClick, (event)=>{
setChecked((prevChecked)=>!prevChecked
);
if (isFormControl) {
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(); // if switch is in a form, stop propagation from the button so that we only propagate
// one click event (from the input). We propagate changes from an input so that native
// form validation works and form events reflect switch updates.
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
}
})
})), isFormControl && /*#__PURE__*/ $cWV9h$react.createElement($4465bdeb0ef4ccd7$var$BubbleInput, {
control: button,
bubbles: !hasConsumerStoppedPropagationRef.current,
name: name,
value: value,
checked: checked,
required: required,
disabled: disabled // We transform because the input is absolutely positioned but we have
,
style: {
transform: 'translateX(-100%)'
}
}));
});
/*#__PURE__*/ Object.assign($4465bdeb0ef4ccd7$export$b5d5cf8927ab7262, {
displayName: $4465bdeb0ef4ccd7$var$SWITCH_NAME
});
/* -------------------------------------------------------------------------------------------------
* SwitchThumb
* -----------------------------------------------------------------------------------------------*/ const $4465bdeb0ef4ccd7$var$THUMB_NAME = 'SwitchThumb';
const $4465bdeb0ef4ccd7$export$4d07bf653ea69106 = /*#__PURE__*/ $cWV9h$react.forwardRef((props, forwardedRef)=>{
const { __scopeSwitch: __scopeSwitch , ...thumbProps } = props;
const context = $4465bdeb0ef4ccd7$var$useSwitchContext($4465bdeb0ef4ccd7$var$THUMB_NAME, __scopeSwitch);
return /*#__PURE__*/ $cWV9h$react.createElement($cWV9h$radixuireactprimitive.Primitive.span, ($parcel$interopDefault($cWV9h$babelruntimehelpersextends))({
"data-state": $4465bdeb0ef4ccd7$var$getState(context.checked),
"data-disabled": context.disabled ? '' : undefined
}, thumbProps, {
ref: forwardedRef
}));
});
/*#__PURE__*/ Object.assign($4465bdeb0ef4ccd7$export$4d07bf653ea69106, {
displayName: $4465bdeb0ef4ccd7$var$THUMB_NAME
});
/* ---------------------------------------------------------------------------------------------- */ const $4465bdeb0ef4ccd7$var$BubbleInput = (props)=>{
const { control: control , checked: checked , bubbles: bubbles = true , ...inputProps } = props;
const ref = $cWV9h$react.useRef(null);
const prevChecked = $cWV9h$radixuireactuseprevious.usePrevious(checked);
const controlSize = $cWV9h$radixuireactusesize.useSize(control); // Bubble checked change to parents (e.g form change event)
$cWV9h$react.useEffect(()=>{
const input = ref.current;
const inputProto = window.HTMLInputElement.prototype;
const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked');
const setChecked = descriptor.set;
if (prevChecked !== checked && setChecked) {
const event = new Event('click', {
bubbles: bubbles
});
setChecked.call(input, checked);
input.dispatchEvent(event);
}
}, [
prevChecked,
checked,
bubbles
]);
return /*#__PURE__*/ $cWV9h$react.createElement("input", ($parcel$interopDefault($cWV9h$babelruntimehelpersextends))({
type: "checkbox",
"aria-hidden": true,
defaultChecked: checked
}, inputProps, {
tabIndex: -1,
ref: ref,
style: {
...props.style,
...controlSize,
position: 'absolute',
pointerEvents: 'none',
opacity: 0,
margin: 0
}
}));
};
function $4465bdeb0ef4ccd7$var$getState(checked) {
return checked ? 'checked' : 'unchecked';
}
const $4465bdeb0ef4ccd7$export$be92b6f5f03c0fe9 = $4465bdeb0ef4ccd7$export$b5d5cf8927ab7262;
const $4465bdeb0ef4ccd7$export$6521433ed15a34db = $4465bdeb0ef4ccd7$export$4d07bf653ea69106;
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"mappings":";;;;;;;;;;;;;;;;;;;;;;A;;;;;;;;;ACYA;;oGAEA,CAEA,MAAMa,iCAAW,GAAG,QAApB,AAAA;AAGA,MAAM,CAACC,yCAAD,EAAsBd,yCAAtB,CAAA,GAA2CQ,6CAAkB,CAACK,iCAAD,CAAnE,AAAA;AAGA,MAAM,CAACE,oCAAD,EAAiBC,sCAAjB,CAAA,GAAqCF,yCAAmB,CAAqBD,iCAArB,CAA9D,AAAA;AAWA,MAAMZ,yCAAM,GAAA,aAAGI,CAAAA,uBAAA,CACb,CAACa,KAAD,EAAkCC,YAAlC,GAAmD;IACjD,MAAM,E,eACJC,aADI,CAAA,E,MAEJC,IAFI,CAAA,EAGJC,OAAO,EAAEC,WAHL,CAAA,E,gBAIJC,cAJI,CAAA,E,UAKJC,QALI,CAAA,E,UAMJC,QANI,CAAA,SAOJC,KAAK,GAAG,IAPJ,G,iBAQJC,eARI,CAAA,EASJ,GAAGC,WAAH,EATI,GAUFX,KAVJ,AAAM;IAWN,MAAM,CAACY,MAAD,EAASC,SAAT,CAAA,GAAsB1B,qBAAA,CAAyC,IAAzC,CAA5B,AAAA;IACA,MAAM4B,YAAY,GAAG1B,8CAAe,CAACY,YAAD,EAAgBe,CAAAA,IAAD,GAAUH,SAAS,CAACG,IAAD,CAAlC;IAAA,CAApC,AAAA;IACA,MAAMC,gCAAgC,GAAG9B,mBAAA,CAAa,KAAb,CAAzC,AAdiD,EAejD,iFADA;IAEA,MAAMgC,aAAa,GAAGP,MAAM,GAAGQ,OAAO,CAACR,MAAM,CAACS,OAAP,CAAe,MAAf,CAAD,CAAV,GAAqC,IAAjE,AAAA;IACA,MAAM,CAAC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EAAE,CAARA;SANK;KAPT,CAAA,CADF,CACE;CApBJ,AAqCC;AAED,SAASnC,8BAAT,CAAkBtB,OAAlB,EAAoC;IAClC,OAAOA,OAAO,GAAG,SAAH,GAAe,WAA7B,CAAA;CACD;AAED,MAAMnB,yCAAI,GAAGF,yCAAb,AAAA;AACA,MAAMG,yCAAK,GAAGF,yCAAd,AAAA;;ADvLA","sources":["packages/react/switch/src/index.ts","packages/react/switch/src/Switch.tsx"],"sourcesContent":["export {\n createSwitchScope,\n //\n Switch,\n SwitchThumb,\n //\n Root,\n Thumb,\n} from './Switch';\nexport type { SwitchProps, SwitchThumbProps } from './Switch';\n","import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { usePrevious } from '@radix-ui/react-use-previous';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Primitive } from '@radix-ui/react-primitive';\n\Line truncated
+144
View File
@@ -0,0 +1,144 @@
import $irPIl$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
import {forwardRef as $irPIl$forwardRef, useState as $irPIl$useState, useRef as $irPIl$useRef, createElement as $irPIl$createElement, useEffect as $irPIl$useEffect} from "react";
import {composeEventHandlers as $irPIl$composeEventHandlers} from "@radix-ui/primitive";
import {useComposedRefs as $irPIl$useComposedRefs} from "@radix-ui/react-compose-refs";
import {createContextScope as $irPIl$createContextScope} from "@radix-ui/react-context";
import {useControllableState as $irPIl$useControllableState} from "@radix-ui/react-use-controllable-state";
import {usePrevious as $irPIl$usePrevious} from "@radix-ui/react-use-previous";
import {useSize as $irPIl$useSize} from "@radix-ui/react-use-size";
import {Primitive as $irPIl$Primitive} from "@radix-ui/react-primitive";
/* -------------------------------------------------------------------------------------------------
* Switch
* -----------------------------------------------------------------------------------------------*/ const $6be4966fd9bbc698$var$SWITCH_NAME = 'Switch';
const [$6be4966fd9bbc698$var$createSwitchContext, $6be4966fd9bbc698$export$cf7f5f17f69cbd43] = $irPIl$createContextScope($6be4966fd9bbc698$var$SWITCH_NAME);
const [$6be4966fd9bbc698$var$SwitchProvider, $6be4966fd9bbc698$var$useSwitchContext] = $6be4966fd9bbc698$var$createSwitchContext($6be4966fd9bbc698$var$SWITCH_NAME);
const $6be4966fd9bbc698$export$b5d5cf8927ab7262 = /*#__PURE__*/ $irPIl$forwardRef((props, forwardedRef)=>{
const { __scopeSwitch: __scopeSwitch , name: name , checked: checkedProp , defaultChecked: defaultChecked , required: required , disabled: disabled , value: value = 'on' , onCheckedChange: onCheckedChange , ...switchProps } = props;
const [button, setButton] = $irPIl$useState(null);
const composedRefs = $irPIl$useComposedRefs(forwardedRef, (node)=>setButton(node)
);
const hasConsumerStoppedPropagationRef = $irPIl$useRef(false); // We set this to true by default so that events bubble to forms without JS (SSR)
const isFormControl = button ? Boolean(button.closest('form')) : true;
const [checked = false, setChecked] = $irPIl$useControllableState({
prop: checkedProp,
defaultProp: defaultChecked,
onChange: onCheckedChange
});
return /*#__PURE__*/ $irPIl$createElement($6be4966fd9bbc698$var$SwitchProvider, {
scope: __scopeSwitch,
checked: checked,
disabled: disabled
}, /*#__PURE__*/ $irPIl$createElement($irPIl$Primitive.button, $irPIl$babelruntimehelpersesmextends({
type: "button",
role: "switch",
"aria-checked": checked,
"aria-required": required,
"data-state": $6be4966fd9bbc698$var$getState(checked),
"data-disabled": disabled ? '' : undefined,
disabled: disabled,
value: value
}, switchProps, {
ref: composedRefs,
onClick: $irPIl$composeEventHandlers(props.onClick, (event)=>{
setChecked((prevChecked)=>!prevChecked
);
if (isFormControl) {
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(); // if switch is in a form, stop propagation from the button so that we only propagate
// one click event (from the input). We propagate changes from an input so that native
// form validation works and form events reflect switch updates.
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
}
})
})), isFormControl && /*#__PURE__*/ $irPIl$createElement($6be4966fd9bbc698$var$BubbleInput, {
control: button,
bubbles: !hasConsumerStoppedPropagationRef.current,
name: name,
value: value,
checked: checked,
required: required,
disabled: disabled // We transform because the input is absolutely positioned but we have
,
style: {
transform: 'translateX(-100%)'
}
}));
});
/*#__PURE__*/ Object.assign($6be4966fd9bbc698$export$b5d5cf8927ab7262, {
displayName: $6be4966fd9bbc698$var$SWITCH_NAME
});
/* -------------------------------------------------------------------------------------------------
* SwitchThumb
* -----------------------------------------------------------------------------------------------*/ const $6be4966fd9bbc698$var$THUMB_NAME = 'SwitchThumb';
const $6be4966fd9bbc698$export$4d07bf653ea69106 = /*#__PURE__*/ $irPIl$forwardRef((props, forwardedRef)=>{
const { __scopeSwitch: __scopeSwitch , ...thumbProps } = props;
const context = $6be4966fd9bbc698$var$useSwitchContext($6be4966fd9bbc698$var$THUMB_NAME, __scopeSwitch);
return /*#__PURE__*/ $irPIl$createElement($irPIl$Primitive.span, $irPIl$babelruntimehelpersesmextends({
"data-state": $6be4966fd9bbc698$var$getState(context.checked),
"data-disabled": context.disabled ? '' : undefined
}, thumbProps, {
ref: forwardedRef
}));
});
/*#__PURE__*/ Object.assign($6be4966fd9bbc698$export$4d07bf653ea69106, {
displayName: $6be4966fd9bbc698$var$THUMB_NAME
});
/* ---------------------------------------------------------------------------------------------- */ const $6be4966fd9bbc698$var$BubbleInput = (props)=>{
const { control: control , checked: checked , bubbles: bubbles = true , ...inputProps } = props;
const ref = $irPIl$useRef(null);
const prevChecked = $irPIl$usePrevious(checked);
const controlSize = $irPIl$useSize(control); // Bubble checked change to parents (e.g form change event)
$irPIl$useEffect(()=>{
const input = ref.current;
const inputProto = window.HTMLInputElement.prototype;
const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked');
const setChecked = descriptor.set;
if (prevChecked !== checked && setChecked) {
const event = new Event('click', {
bubbles: bubbles
});
setChecked.call(input, checked);
input.dispatchEvent(event);
}
}, [
prevChecked,
checked,
bubbles
]);
return /*#__PURE__*/ $irPIl$createElement("input", $irPIl$babelruntimehelpersesmextends({
type: "checkbox",
"aria-hidden": true,
defaultChecked: checked
}, inputProps, {
tabIndex: -1,
ref: ref,
style: {
...props.style,
...controlSize,
position: 'absolute',
pointerEvents: 'none',
opacity: 0,
margin: 0
}
}));
};
function $6be4966fd9bbc698$var$getState(checked) {
return checked ? 'checked' : 'unchecked';
}
const $6be4966fd9bbc698$export$be92b6f5f03c0fe9 = $6be4966fd9bbc698$export$b5d5cf8927ab7262;
const $6be4966fd9bbc698$export$6521433ed15a34db = $6be4966fd9bbc698$export$4d07bf653ea69106;
export {$6be4966fd9bbc698$export$cf7f5f17f69cbd43 as createSwitchScope, $6be4966fd9bbc698$export$b5d5cf8927ab7262 as Switch, $6be4966fd9bbc698$export$4d07bf653ea69106 as SwitchThumb, $6be4966fd9bbc698$export$be92b6f5f03c0fe9 as Root, $6be4966fd9bbc698$export$6521433ed15a34db as Thumb};
//# sourceMappingURL=index.mjs.map
+1
View File
@@ -0,0 +1 @@
{"mappings":";;;;;;;;;;A;;;;;;;;;ACYA;;oGAEA,CAEA,MAAMa,iCAAW,GAAG,QAApB,AAAA;AAGA,MAAM,CAACC,yCAAD,EAAsBd,yCAAtB,CAAA,GAA2CQ,yBAAkB,CAACK,iCAAD,CAAnE,AAAA;AAGA,MAAM,CAACE,oCAAD,EAAiBC,sCAAjB,CAAA,GAAqCF,yCAAmB,CAAqBD,iCAArB,CAA9D,AAAA;AAWA,MAAMZ,yCAAM,GAAA,aAAGI,CAAAA,iBAAA,CACb,CAACa,KAAD,EAAkCC,YAAlC,GAAmD;IACjD,MAAM,E,eACJC,aADI,CAAA,E,MAEJC,IAFI,CAAA,EAGJC,OAAO,EAAEC,WAHL,CAAA,E,gBAIJC,cAJI,CAAA,E,UAKJC,QALI,CAAA,E,UAMJC,QANI,CAAA,SAOJC,KAAK,GAAG,IAPJ,G,iBAQJC,eARI,CAAA,EASJ,GAAGC,WAAH,EATI,GAUFX,KAVJ,AAAM;IAWN,MAAM,CAACY,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vB;KAVH,CAUC,CAAA;IAED,OAAA,aACE,CAAA,oBADF,CAAA,OAAA,EAAA,oCAAA,CAAA;QAEI,IAAI,EAAC,UADP;QAEE,aAAA,EAAA,IAFF;QAGE,cAAc,EAAEpC,OAAhB;KAHF,EAIMqC,UAJN,EAAA;QAKE,QAAQ,EAAE,EALZ;QAME,GAAG,EAAEC,GANP;QAOE,KAAK,EAAE;YACL,GAAG1C,KAAK,CAACyD,KADJ;YAEL,GAAGd,WAFE;YAGLe,QAAQ,EAAE,UAHL;YAILC,aAAa,EAAE,MAJV;YAKLC,OAAO,EAAE,CALJ;YAMLC,MAAM,EAAE,CAARA;SANK;KAPT,CAAA,CADF,CACE;CApBJ,AAqCC;AAED,SAASnC,8BAAT,CAAkBtB,OAAlB,EAAoC;IAClC,OAAOA,OAAO,GAAG,SAAH,GAAe,WAA7B,CAAA;CACD;AAED,MAAMnB,yCAAI,GAAGF,yCAAb,AAAA;AACA,MAAMG,yCAAK,GAAGF,yCAAd,AAAA;;ADvLA","sources":["packages/react/switch/src/index.ts","packages/react/switch/src/Switch.tsx"],"sourcesContent":["export {\n createSwitchScope,\n //\n Switch,\n SwitchThumb,\n //\n Root,\n Thumb,\n} from './Switch';\nexport type { SwitchProps, SwitchThumbProps } from './Switch';\n","import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport { usePrevious } from '@radix-ui/react-use-previous';\nimport { useSize } from '@radix-ui/react-use-size';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type * aLine truncated
+62
View File
@@ -0,0 +1,62 @@
{
"name": "@radix-ui/react-switch",
"version": "1.0.3",
"license": "MIT",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"source": "./src/index.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist",
"README.md"
],
"sideEffects": false,
"scripts": {
"clean": "rm -rf dist",
"version": "yarn version"
},
"dependencies": {
"@babel/runtime": "^7.13.10",
"@radix-ui/primitive": "1.0.1",
"@radix-ui/react-compose-refs": "1.0.1",
"@radix-ui/react-context": "1.0.1",
"@radix-ui/react-primitive": "1.0.3",
"@radix-ui/react-use-controllable-state": "1.0.1",
"@radix-ui/react-use-previous": "1.0.1",
"@radix-ui/react-use-size": "1.0.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0",
"react-dom": "^16.8 || ^17.0 || ^18.0"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
},
"homepage": "https://radix-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/radix-ui/primitives.git"
},
"bugs": {
"url": "https://github.com/radix-ui/primitives/issues"
}
}