@radix-ui/react-label 0.1.6-rc.2 → 0.1.6-rc.5

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.
@@ -1 +1 @@
1
- {"mappings":"A;A;A;AAqBA,0BAA0B,MAAM,wBAAwB,CAAC,OAAO,UAAU,IAAI,CAAC,CAAC;AAChF,2BAAqB,SAAQ,kBAAkB;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,OAAA,MAAM,yFAgEJ,CAAC;AAMH,OAAA,MAAM,iFASL,CAAC;AAEF,OAAA,MAAM,wFAAY,CAAC","sources":["./packages/react/label/src/packages/react/label/src/Label.tsx","./packages/react/label/src/packages/react/label/src/index.ts"],"sourcesContent":[null,null],"names":[],"version":3,"file":"index.d.ts.map"}
1
+ {"mappings":";;;AAqBA,0BAA0B,MAAM,wBAAwB,CAAC,OAAO,UAAU,IAAI,CAAC,CAAC;AAChF,2BAAqB,SAAQ,kBAAkB;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,OAAA,MAAM,yFAgEJ,CAAC;AAMH,OAAA,MAAM,iFASL,CAAC;AAEF,OAAA,MAAM,wFAAY,CAAC","sources":["packages/react/label/src/packages/react/label/src/Label.tsx","packages/react/label/src/packages/react/label/src/index.ts","packages/react/label/src/index.ts"],"sourcesContent":[null,null,"export * from './Label';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.js CHANGED
@@ -1,2 +1,135 @@
1
- var e,r,t,n=require("@radix-ui/react-id").useId,l=require("@radix-ui/react-primitive").Primitive,u=require("@radix-ui/react-compose-refs").useComposedRefs,o=require("@radix-ui/react-context").createContext,i=(e={},r=require("react"),Object.keys(r).forEach((function(t){"default"!==t&&"__esModule"!==t&&Object.defineProperty(e,t,{enumerable:!0,get:function(){return r[t]}})})),e),a=(t=require("@babel/runtime/helpers/extends"))&&t.__esModule?t.default:t;const[c,s]=o("Label",{id:void 0,controlRef:{current:null}}),d=/*#__PURE__*/i.forwardRef(((e,r)=>{const{htmlFor:t,id:o,...s}=e,d=i.useRef(null),f=i.useRef(null),b=u(r,f),v=n(o);return i.useEffect((()=>{if(t){const e=document.getElementById(t);if(f.current&&e){const r=()=>e.getAttribute("aria-labelledby"),t=[v,r()].filter(Boolean).join(" ");return e.setAttribute("aria-labelledby",t),d.current=e,()=>{var t;const n=null===(t=r())||void 0===t?void 0:t.replace(v,"");""===n?e.removeAttribute("aria-labelledby"):n&&e.setAttribute("aria-labelledby",n)}}}}),[v,t]),/*#__PURE__*/i.createElement(c,{id:v,controlRef:d},/*#__PURE__*/i.createElement(l.span,a({role:"label",id:v},s,{ref:b,onMouseDown:r=>{var t;null===(t=e.onMouseDown)||void 0===t||t.call(e,r),!r.defaultPrevented&&r.detail>1&&r.preventDefault()},onClick:r=>{var t;if(null===(t=e.onClick)||void 0===t||t.call(e,r),!d.current||r.defaultPrevented)return;const n=d.current.contains(r.target),l=!0===r.isTrusted;!n&&l&&(d.current.click(),d.current.focus())}})))}));exports.Label=d;exports.useLabelContext=e=>{const r=s("LabelConsumer"),{controlRef:t}=r;return i.useEffect((()=>{e&&(t.current=e)}),[e,t]),r.id};const f=d;exports.Root=f;
1
+ var $RyX6d$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
2
+ var $RyX6d$react = require("react");
3
+ var $RyX6d$radixuireactcontext = require("@radix-ui/react-context");
4
+ var $RyX6d$radixuireactcomposerefs = require("@radix-ui/react-compose-refs");
5
+ var $RyX6d$radixuireactprimitive = require("@radix-ui/react-primitive");
6
+ var $RyX6d$radixuireactid = require("@radix-ui/react-id");
7
+
8
+ function $parcel$exportWildcard(dest, source) {
9
+ Object.keys(source).forEach(function(key) {
10
+ if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
11
+ return;
12
+ }
13
+
14
+ Object.defineProperty(dest, key, {
15
+ enumerable: true,
16
+ get: function get() {
17
+ return source[key];
18
+ }
19
+ });
20
+ });
21
+
22
+ return dest;
23
+ }
24
+ function $parcel$interopDefault(a) {
25
+ return a && a.__esModule ? a.default : a;
26
+ }
27
+ function $parcel$export(e, n, v, s) {
28
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
29
+ }
30
+ var $2583d9c3eccdd4e2$exports = {};
31
+
32
+ $parcel$export($2583d9c3eccdd4e2$exports, "Label", () => $2583d9c3eccdd4e2$export$b04be29aa201d4f5);
33
+ $parcel$export($2583d9c3eccdd4e2$exports, "useLabelContext", () => $2583d9c3eccdd4e2$export$feddbbf47baabdb9);
34
+ $parcel$export($2583d9c3eccdd4e2$exports, "Root", () => $2583d9c3eccdd4e2$export$be92b6f5f03c0fe9);
35
+
36
+
37
+
38
+
39
+
40
+
41
+ /* -------------------------------------------------------------------------------------------------
42
+ * Label
43
+ * -----------------------------------------------------------------------------------------------*/ const $2583d9c3eccdd4e2$var$NAME = 'Label';
44
+ const [$2583d9c3eccdd4e2$var$LabelProvider, $2583d9c3eccdd4e2$var$useLabelContextImpl] = $RyX6d$radixuireactcontext.createContext($2583d9c3eccdd4e2$var$NAME, {
45
+ id: undefined,
46
+ controlRef: {
47
+ current: null
48
+ }
49
+ });
50
+ const $2583d9c3eccdd4e2$export$b04be29aa201d4f5 = /*#__PURE__*/ $RyX6d$react.forwardRef((props, forwardedRef)=>{
51
+ const { htmlFor: htmlFor , id: idProp , ...labelProps } = props;
52
+ const controlRef = $RyX6d$react.useRef(null);
53
+ const ref = $RyX6d$react.useRef(null);
54
+ const composedRefs = $RyX6d$radixuireactcomposerefs.useComposedRefs(forwardedRef, ref);
55
+ const id = $RyX6d$radixuireactid.useId(idProp);
56
+ $RyX6d$react.useEffect(()=>{
57
+ if (htmlFor) {
58
+ const element = document.getElementById(htmlFor);
59
+ const label = ref.current;
60
+ if (label && element) {
61
+ const getAriaLabel = ()=>element.getAttribute('aria-labelledby')
62
+ ;
63
+ const ariaLabelledBy1 = [
64
+ id,
65
+ getAriaLabel()
66
+ ].filter(Boolean).join(' ');
67
+ element.setAttribute('aria-labelledby', ariaLabelledBy1);
68
+ controlRef.current = element;
69
+ return ()=>{
70
+ var _getAriaLabel;
71
+ /**
72
+ * We get the latest attribute value because at the time that this cleanup fires,
73
+ * the values from the closure may have changed.
74
+ */ const ariaLabelledBy = (_getAriaLabel = getAriaLabel()) === null || _getAriaLabel === void 0 ? void 0 : _getAriaLabel.replace(id, '');
75
+ if (ariaLabelledBy === '') element.removeAttribute('aria-labelledby');
76
+ else if (ariaLabelledBy) element.setAttribute('aria-labelledby', ariaLabelledBy);
77
+ };
78
+ }
79
+ }
80
+ }, [
81
+ id,
82
+ htmlFor
83
+ ]);
84
+ return /*#__PURE__*/ $RyX6d$react.createElement($2583d9c3eccdd4e2$var$LabelProvider, {
85
+ id: id,
86
+ controlRef: controlRef
87
+ }, /*#__PURE__*/ $RyX6d$react.createElement($RyX6d$radixuireactprimitive.Primitive.span, ($parcel$interopDefault($RyX6d$babelruntimehelpersextends))({
88
+ role: "label",
89
+ id: id
90
+ }, labelProps, {
91
+ ref: composedRefs,
92
+ onMouseDown: (event)=>{
93
+ var _props$onMouseDown;
94
+ (_props$onMouseDown = props.onMouseDown) === null || _props$onMouseDown === void 0 || _props$onMouseDown.call(props, event); // prevent text selection when double clicking label
95
+ if (!event.defaultPrevented && event.detail > 1) event.preventDefault();
96
+ },
97
+ onClick: (event)=>{
98
+ var _props$onClick;
99
+ (_props$onClick = props.onClick) === null || _props$onClick === void 0 || _props$onClick.call(props, event);
100
+ if (!controlRef.current || event.defaultPrevented) return;
101
+ const isClickingControl = controlRef.current.contains(event.target); // Ensure event was generated by a user action
102
+ // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted
103
+ const isUserClick = event.isTrusted === true;
104
+ /**
105
+ * When a label is wrapped around the control it labels, we trigger the appropriate events
106
+ * on the control when the label is clicked. We do nothing if the user is already clicking the
107
+ * control inside the label.
108
+ */ if (!isClickingControl && isUserClick) {
109
+ controlRef.current.click();
110
+ controlRef.current.focus();
111
+ }
112
+ }
113
+ })));
114
+ });
115
+ /*#__PURE__*/ Object.assign($2583d9c3eccdd4e2$export$b04be29aa201d4f5, {
116
+ displayName: $2583d9c3eccdd4e2$var$NAME
117
+ });
118
+ /* -----------------------------------------------------------------------------------------------*/ const $2583d9c3eccdd4e2$export$feddbbf47baabdb9 = (element)=>{
119
+ const context = $2583d9c3eccdd4e2$var$useLabelContextImpl('LabelConsumer');
120
+ const { controlRef: controlRef } = context;
121
+ $RyX6d$react.useEffect(()=>{
122
+ if (element) controlRef.current = element;
123
+ }, [
124
+ element,
125
+ controlRef
126
+ ]);
127
+ return context.id;
128
+ };
129
+ const $2583d9c3eccdd4e2$export$be92b6f5f03c0fe9 = $2583d9c3eccdd4e2$export$b04be29aa201d4f5;
130
+
131
+
132
+ $parcel$exportWildcard(module.exports, $2583d9c3eccdd4e2$exports);
133
+
134
+
2
135
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":"IAYgCA,EAAMC,EAZNC,yMAYAF,KAAMC,mBACpCE,OAAOC,KAAKH,GAAQI,SAAQ,SAASC,GACvB,YAARA,GAA6B,eAARA,GAIzBH,OAAOI,eAAeP,EAAMM,EAAK,CAC/BE,YAAY,EACZC,IAAK,WACH,OAAOR,EAAOK,SAKbN,MA1BuBE,8CAClBA,EAAEQ,WAAaR,EAAES,QAAUT,ECWzC,MAGOU,EAAeC,GAAuBC,EAHhC,QAGuE,CAClFC,QAAIC,EACJC,WAAY,CAAEC,QAAS,QASnBC,eAAQC,EAAMC,YAAqC,CAACC,EAAOC,KAC/D,MAAMC,QAAEA,EAAST,GAAIU,KAAWC,GAAeJ,EACzCL,EAAaG,EAAMO,OAA2B,MAC9CC,EAAMR,EAAMO,OAAwB,MACpCE,EAAeC,EAAgBP,EAAcK,GAC7Cb,EAAKgB,EAAMN,GA2BjB,OAzBAL,EAAMY,WAAU,KACd,GAAIR,EAAS,CACX,MAAMS,EAAUC,SAASC,eAAeX,GAExC,GADcI,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ourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$reexport(e, n, v) {\n Object.defineProperty(e, n, {get: v, enumerable: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","import * as React from 'react';\nimport { createContext } from '@radix-ui/react-context';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useId } from '@radix-ui/react-id';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * Label\n * -----------------------------------------------------------------------------------------------*/\n\nconst NAME = 'Label';\n\ntype LabelContextValue = { id?: string; controlRef: React.MutableRefObject<HTMLElement | null> };\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n});\n\ntype LabelElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface LabelProps extends PrimitiveSpanProps {\n htmlFor?: string;\n}\n\nconst Label = React.forwardRef<LabelElement, LabelProps>((props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props;\n const controlRef = React.useRef<HTMLElement | null>(null);\n const ref = React.useRef<HTMLSpanElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n const id = useId(idProp);\n\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor);\n const label = ref.current;\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby');\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ');\n element.setAttribute('aria-labelledby', ariaLabelledBy);\n controlRef.current = element;\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n const ariaLabelledBy = getAriaLabel()?.replace(id, '');\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby');\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy);\n }\n };\n }\n }\n }, [id, htmlFor]);\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <Primitive.span\n role=\"label\"\n id={id}\n {...labelProps}\n ref={composedRefs}\n onMouseDown={(event) => {\n props.onMouseDown?.(event);\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) event.preventDefault();\n }}\n onClick={(event) => {\n props.onClick?.(event);\n if (!controlRef.current || event.defaultPrevented) return;\n const isClickingControl = controlRef.current.contains(event.target as Node);\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true;\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click();\n controlRef.current.focus();\n }\n }}\n />\n </LabelProvider>\n );\n});\n\nLabel.displayName = NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer');\n const { controlRef } = context;\n\n React.useEffect(() => {\n if (element) controlRef.current = element;\n }, [element, controlRef]);\n\n return context.id;\n};\n\nconst Root = Label;\n\nexport {\n Label,\n //\n Root,\n //\n useLabelContext,\n};\nexport type { LabelProps };\n"],"names":["dest","source","a","Object","keys","forEach","key","defineProperty","enumerable","get","__esModule","default","LabelProvider","useLabelContextImpl","createContext","id","undefined","controlRef","current","Label","React","forwardRef","props","forwardedRef","htmlFor","idProp","labelProps","useRef","ref","composedRefs","useComposedRefs","useId","useEffect","element","document","getElementById","getAriaLabel","getAttribute","ariaLabelledBy","filter","Boolean","join","setAttribute","_getAriaLabel","replace","removeAttribute","_react","createElement","$cc55afdc86a89367fbda1ce67c935ecf$var$LabelProvider","Primitive","span","_babelRuntimeHelpersExtends","role","onMouseDown","event","_props$onMouseDown","call","defaultPrevented","detail","preventDefault","onClick","_props$onClick","isClickingControl","contains","target","isUserClick","isTrusted","click","focus","context","Root"],"version":3,"file":"index.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A;;;;;;ACQA;;oGAEA,CAEA,MAAMK,0BAAI,GAAG,OAAb,AAAA;AAGA,MAAM,CAACC,mCAAD,EAAgBC,yCAAhB,CAAA,GAAuCN,wCAAa,CAAoBI,0BAApB,EAA0B;IAClFG,EAAE,EAAEC,SAD8E;IAElFC,UAAU,EAAE;QAAEC,OAAO,EAAE,IAATA;KAAF;CAF4C,CAA1D,AAAoF;AAWpF,MAAMC,yCAAK,GAAA,aAAGZ,CAAAA,uBAAA,CAA2C,CAACc,KAAD,EAAQC,YAAR,GAAyB;IAChF,MAAM,E,SAAEC,OAAF,CAAA,EAAWR,EAAE,EAAES,MAAf,CAAA,EAAuB,GAAGC,UAAH,EAAvB,GAAyCJ,KAA/C,AAAM;IACN,MAAMJ,UAAU,GAAGV,mBAAA,CAAiC,IAAjC,CAAnB,AAAA;IACA,MAAMoB,GAAG,GAAGpB,mBAAA,CAA8B,IAA9B,CAAZ,AAAA;IACA,MAAMqB,YAAY,GAAGnB,8CAAe,CAACa,YAAD,EAAeK,GAAf,CAApC,AAAA;IACA,MAAMZ,EAAE,GAAGJ,2BAAK,CAACa,MAAD,CAAhB,AAAA;IAE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AED,aAAA,CAAA,MAAA,CAAA,MAAA,CAAA,yCAAA,EAAA;IAAA,WAAA,EAAA,0BAAA;CAAA,CAAA,CAAA;AAEA,oGAAA,CAEA,MAAMuC,yCAAe,GAAI1B,CAAAA,OAAD,GAAkC;IACxD,MAAM2B,OAAO,GAAG3C,yCAAmB,CAAC,eAAD,CAAnC,AAAA;IACA,MAAM,E,YAAEG,UAAAA,CAAAA,EAAF,GAAiBwC,OAAvB,AAAM;IAENlD,sBAAA,CAAgB,IAAM;QACpB,IAAIuB,OAAJ,EAAab,UAAU,CAACC,OAAX,GAAqBY,OAArB,CAAb;KADF,EAEG;QAACA,OAAD;QAAUb,UAAV;KAFH,CAEC,CAAA;IAED,OAAOwC,OAAO,CAAC1C,EAAf,CAAA;CARF,AASC;AAED,MAAM2C,yCAAI,GAAGvC,yCAAb,AAAA;;AD3GA","sources":["packages/react/label/src/index.ts","packages/react/label/src/Label.tsx"],"sourcesContent":["export * from './Label';\n","import * as React from 'react';\nimport { createContext } from '@radix-ui/react-context';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useId } from '@radix-ui/react-id';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * Label\n * -----------------------------------------------------------------------------------------------*/\n\nconst NAME = 'Label';\n\ntype LabelContextValue = { id?: string; controlRef: React.MutableRefObject<HTMLElement | null> };\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n});\n\ntype LabelElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface LabelProps extends PrimitiveSpanProps {\n htmlFor?: string;\n}\n\nconst Label = React.forwardRef<LabelElement, LabelProps>((props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props;\n const controlRef = React.useRef<HTMLElement | null>(null);\n const ref = React.useRef<HTMLSpanElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n const id = useId(idProp);\n\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor);\n const label = ref.current;\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby');\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ');\n element.setAttribute('aria-labelledby', ariaLabelledBy);\n controlRef.current = element;\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n const ariaLabelledBy = getAriaLabel()?.replace(id, '');\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby');\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy);\n }\n };\n }\n }\n }, [id, htmlFor]);\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <Primitive.span\n role=\"label\"\n id={id}\n {...labelProps}\n ref={composedRefs}\n onMouseDown={(event) => {\n props.onMouseDown?.(event);\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) event.preventDefault();\n }}\n onClick={(event) => {\n props.onClick?.(event);\n if (!controlRef.current || event.defaultPrevented) return;\n const isClickingControl = controlRef.current.contains(event.target as Node);\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true;\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click();\n controlRef.current.focus();\n }\n }}\n />\n </LabelProvider>\n );\n});\n\nLabel.displayName = NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer');\n const { controlRef } = context;\n\n React.useEffect(() => {\n if (element) controlRef.current = element;\n }, [element, controlRef]);\n\n return context.id;\n};\n\nconst Root = Label;\n\nexport {\n Label,\n //\n Root,\n //\n useLabelContext,\n};\nexport type { LabelProps };\n"],"names":["React","createContext","useComposedRefs","Primitive","useId","NAME","LabelProvider","useLabelContextImpl","id","undefined","controlRef","current","Label","forwardRef","props","forwardedRef","htmlFor","idProp","labelProps","useRef","ref","composedRefs","useEffect","element","document","getElementById","label","getAriaLabel","getAttribute","ariaLabelledBy","filter","Boolean","join","setAttribute","replace","removeAttribute","event","onMouseDown","defaultPrevented","detail","preventDefault","onClick","isClickingControl","contains","target","isUserClick","isTrusted","click","focus","useLabelContext","context","Root"],"version":3,"file":"index.js.map"}
@@ -1,2 +1,116 @@
1
- import{useId as e}from"@radix-ui/react-id";import{Primitive as t}from"@radix-ui/react-primitive";import{useComposedRefs as r}from"@radix-ui/react-compose-refs";import{createContext as o}from"@radix-ui/react-context";import*as l from"react";import n from"@babel/runtime/helpers/esm/extends";const[i,a]=o("Label",{id:void 0,controlRef:{current:null}});export const Label=/*#__PURE__*/l.forwardRef(((o,a)=>{const{htmlFor:c,id:u,...s}=o,d=l.useRef(null),f=l.useRef(null),m=r(a,f),b=e(u);return l.useEffect((()=>{if(c){const e=document.getElementById(c);if(f.current&&e){const t=()=>e.getAttribute("aria-labelledby"),r=[b,t()].filter(Boolean).join(" ");return e.setAttribute("aria-labelledby",r),d.current=e,()=>{var r;const o=null===(r=t())||void 0===r?void 0:r.replace(b,"");""===o?e.removeAttribute("aria-labelledby"):o&&e.setAttribute("aria-labelledby",o)}}}}),[b,c]),/*#__PURE__*/l.createElement(i,{id:b,controlRef:d},/*#__PURE__*/l.createElement(t.span,n({role:"label",id:b},s,{ref:m,onMouseDown:e=>{var t;null===(t=o.onMouseDown)||void 0===t||t.call(o,e),!e.defaultPrevented&&e.detail>1&&e.preventDefault()},onClick:e=>{var t;if(null===(t=o.onClick)||void 0===t||t.call(o,e),!d.current||e.defaultPrevented)return;const r=d.current.contains(e.target),l=!0===e.isTrusted;!r&&l&&(d.current.click(),d.current.focus())}})))}));/*#__PURE__*/export const useLabelContext=e=>{const t=a("LabelConsumer"),{controlRef:r}=t;return l.useEffect((()=>{e&&(r.current=e)}),[e,r]),t.id};export const Root=Label;
1
+ import $7V4JZ$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
2
+ import {forwardRef as $7V4JZ$forwardRef, useRef as $7V4JZ$useRef, useEffect as $7V4JZ$useEffect, createElement as $7V4JZ$createElement} from "react";
3
+ import {createContext as $7V4JZ$createContext} from "@radix-ui/react-context";
4
+ import {useComposedRefs as $7V4JZ$useComposedRefs} from "@radix-ui/react-compose-refs";
5
+ import {Primitive as $7V4JZ$Primitive} from "@radix-ui/react-primitive";
6
+ import {useId as $7V4JZ$useId} from "@radix-ui/react-id";
7
+
8
+ function $parcel$export(e, n, v, s) {
9
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
10
+ }
11
+ var $b73a6c6685e72184$exports = {};
12
+
13
+ $parcel$export($b73a6c6685e72184$exports, "Label", () => $b73a6c6685e72184$export$b04be29aa201d4f5);
14
+ $parcel$export($b73a6c6685e72184$exports, "useLabelContext", () => $b73a6c6685e72184$export$feddbbf47baabdb9);
15
+ $parcel$export($b73a6c6685e72184$exports, "Root", () => $b73a6c6685e72184$export$be92b6f5f03c0fe9);
16
+
17
+
18
+
19
+
20
+
21
+
22
+ /* -------------------------------------------------------------------------------------------------
23
+ * Label
24
+ * -----------------------------------------------------------------------------------------------*/ const $b73a6c6685e72184$var$NAME = 'Label';
25
+ const [$b73a6c6685e72184$var$LabelProvider, $b73a6c6685e72184$var$useLabelContextImpl] = $7V4JZ$createContext($b73a6c6685e72184$var$NAME, {
26
+ id: undefined,
27
+ controlRef: {
28
+ current: null
29
+ }
30
+ });
31
+ const $b73a6c6685e72184$export$b04be29aa201d4f5 = /*#__PURE__*/ $7V4JZ$forwardRef((props, forwardedRef)=>{
32
+ const { htmlFor: htmlFor , id: idProp , ...labelProps } = props;
33
+ const controlRef = $7V4JZ$useRef(null);
34
+ const ref = $7V4JZ$useRef(null);
35
+ const composedRefs = $7V4JZ$useComposedRefs(forwardedRef, ref);
36
+ const id = $7V4JZ$useId(idProp);
37
+ $7V4JZ$useEffect(()=>{
38
+ if (htmlFor) {
39
+ const element = document.getElementById(htmlFor);
40
+ const label = ref.current;
41
+ if (label && element) {
42
+ const getAriaLabel = ()=>element.getAttribute('aria-labelledby')
43
+ ;
44
+ const ariaLabelledBy1 = [
45
+ id,
46
+ getAriaLabel()
47
+ ].filter(Boolean).join(' ');
48
+ element.setAttribute('aria-labelledby', ariaLabelledBy1);
49
+ controlRef.current = element;
50
+ return ()=>{
51
+ var _getAriaLabel;
52
+ /**
53
+ * We get the latest attribute value because at the time that this cleanup fires,
54
+ * the values from the closure may have changed.
55
+ */ const ariaLabelledBy = (_getAriaLabel = getAriaLabel()) === null || _getAriaLabel === void 0 ? void 0 : _getAriaLabel.replace(id, '');
56
+ if (ariaLabelledBy === '') element.removeAttribute('aria-labelledby');
57
+ else if (ariaLabelledBy) element.setAttribute('aria-labelledby', ariaLabelledBy);
58
+ };
59
+ }
60
+ }
61
+ }, [
62
+ id,
63
+ htmlFor
64
+ ]);
65
+ return /*#__PURE__*/ $7V4JZ$createElement($b73a6c6685e72184$var$LabelProvider, {
66
+ id: id,
67
+ controlRef: controlRef
68
+ }, /*#__PURE__*/ $7V4JZ$createElement($7V4JZ$Primitive.span, $7V4JZ$babelruntimehelpersesmextends({
69
+ role: "label",
70
+ id: id
71
+ }, labelProps, {
72
+ ref: composedRefs,
73
+ onMouseDown: (event)=>{
74
+ var _props$onMouseDown;
75
+ (_props$onMouseDown = props.onMouseDown) === null || _props$onMouseDown === void 0 || _props$onMouseDown.call(props, event); // prevent text selection when double clicking label
76
+ if (!event.defaultPrevented && event.detail > 1) event.preventDefault();
77
+ },
78
+ onClick: (event)=>{
79
+ var _props$onClick;
80
+ (_props$onClick = props.onClick) === null || _props$onClick === void 0 || _props$onClick.call(props, event);
81
+ if (!controlRef.current || event.defaultPrevented) return;
82
+ const isClickingControl = controlRef.current.contains(event.target); // Ensure event was generated by a user action
83
+ // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted
84
+ const isUserClick = event.isTrusted === true;
85
+ /**
86
+ * When a label is wrapped around the control it labels, we trigger the appropriate events
87
+ * on the control when the label is clicked. We do nothing if the user is already clicking the
88
+ * control inside the label.
89
+ */ if (!isClickingControl && isUserClick) {
90
+ controlRef.current.click();
91
+ controlRef.current.focus();
92
+ }
93
+ }
94
+ })));
95
+ });
96
+ /*#__PURE__*/ Object.assign($b73a6c6685e72184$export$b04be29aa201d4f5, {
97
+ displayName: $b73a6c6685e72184$var$NAME
98
+ });
99
+ /* -----------------------------------------------------------------------------------------------*/ const $b73a6c6685e72184$export$feddbbf47baabdb9 = (element)=>{
100
+ const context = $b73a6c6685e72184$var$useLabelContextImpl('LabelConsumer');
101
+ const { controlRef: controlRef } = context;
102
+ $7V4JZ$useEffect(()=>{
103
+ if (element) controlRef.current = element;
104
+ }, [
105
+ element,
106
+ controlRef
107
+ ]);
108
+ return context.id;
109
+ };
110
+ const $b73a6c6685e72184$export$be92b6f5f03c0fe9 = $b73a6c6685e72184$export$b04be29aa201d4f5;
111
+
112
+
113
+
114
+
115
+ export {$b73a6c6685e72184$export$b04be29aa201d4f5 as Label, $b73a6c6685e72184$export$feddbbf47baabdb9 as useLabelContext, $b73a6c6685e72184$export$be92b6f5f03c0fe9 as Root};
2
116
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"mappings":"kSAYA,MAGOA,EAAeC,GAAuBC,EAHhC,QAGuE,CAClFC,QAAIC,EACJC,WAAY,CAAEC,QAAS,eASzB,MAAMC,mBAAQC,EAAMC,YAAqC,CAACC,EAAOC,KAC/D,MAAMC,QAAEA,EAAST,GAAIU,KAAWC,GAAeJ,EACzCL,EAAaG,EAAMO,OAA2B,MAC9CC,EAAMR,EAAMO,OAAwB,MACpCE,EAAeC,EAAgBP,EAAcK,GAC7Cb,EAAKgB,EAAMN,GA2BjB,OAzBAL,EAAM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,WAGjB,MAAMwD,KAAOpD","sources":["./packages/react/label/src/Label.tsx"],"sourcesContent":["import * as React from 'react';\nimport { createContext } from '@radix-ui/react-context';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useId } from '@radix-ui/react-id';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * Label\n * -----------------------------------------------------------------------------------------------*/\n\nconst NAME = 'Label';\n\ntype LabelContextValue = { id?: string; controlRef: React.MutableRefObject<HTMLElement | null> };\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n});\n\ntype LabelElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface LabelProps extends PrimitiveSpanProps {\n htmlFor?: string;\n}\n\nconst Label = React.forwardRef<LabelElement, LabelProps>((props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props;\n const controlRef = React.useRef<HTMLElement | null>(null);\n const ref = React.useRef<HTMLSpanElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n const id = useId(idProp);\n\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor);\n const label = ref.current;\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby');\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ');\n element.setAttribute('aria-labelledby', ariaLabelledBy);\n controlRef.current = element;\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n const ariaLabelledBy = getAriaLabel()?.replace(id, '');\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby');\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy);\n }\n };\n }\n }\n }, [id, htmlFor]);\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <Primitive.span\n role=\"label\"\n id={id}\n {...labelProps}\n ref={composedRefs}\n onMouseDown={(event) => {\n props.onMouseDown?.(event);\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) event.preventDefault();\n }}\n onClick={(event) => {\n props.onClick?.(event);\n if (!controlRef.current || event.defaultPrevented) return;\n const isClickingControl = controlRef.current.contains(event.target as Node);\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true;\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click();\n controlRef.current.focus();\n }\n }}\n />\n </LabelProvider>\n );\n});\n\nLabel.displayName = NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer');\n const { controlRef } = context;\n\n React.useEffect(() => {\n if (element) controlRef.current = element;\n }, [element, controlRef]);\n\n return context.id;\n};\n\nconst Root = Label;\n\nexport {\n Label,\n //\n Root,\n //\n useLabelContext,\n};\nexport type { LabelProps };\n"],"names":["LabelProvider","useLabelContextImpl","createContext","id","undefined","controlRef","current","Label","React","forwardRef","props","forwardedRef","htmlFor","idProp","labelProps","useRef","ref","composedRefs","useComposedRefs","useId","useEffect","element","document","getElementById","getAriaLabel","getAttribute","ariaLabelledBy","filter","Boolean","join","setAttribute","_getAriaLabel","replace","removeAttribute","_react","createElement","$b835b8b6a05acdec720aee4b37e4b65c$var$LabelProvider","Primitive","span","_babelRuntimeHelpersEsmExtends","role","onMouseDown","event","_props$onMouseDown","call","defaultPrevented","detail","preventDefault","onClick","_props$onClick","isClickingControl","contains","target","isUserClick","isTrusted","click","focus","useLabelContext","context","Root"],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;A;;;;;;ACQA;;oGAEA,CAEA,MAAMK,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/react/label/src/Label.tsx"],"sourcesContent":["export * from './Label';\n","import * as React from 'react';\nimport { createContext } from '@radix-ui/react-context';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useId } from '@radix-ui/react-id';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * Label\n * -----------------------------------------------------------------------------------------------*/\n\nconst NAME = 'Label';\n\ntype LabelContextValue = { id?: string; controlRef: React.MutableRefObject<HTMLElement | null> };\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n});\n\ntype LabelElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface LabelProps extends PrimitiveSpanProps {\n htmlFor?: string;\n}\n\nconst Label = React.forwardRef<LabelElement, LabelProps>((props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props;\n const controlRef = React.useRef<HTMLElement | null>(null);\n const ref = React.useRef<HTMLSpanElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n const id = useId(idProp);\n\n React.useEffect(() => {\n if (htmlFor) {\n const element = document.getElementById(htmlFor);\n const label = ref.current;\n if (label && element) {\n const getAriaLabel = () => element.getAttribute('aria-labelledby');\n const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ');\n element.setAttribute('aria-labelledby', ariaLabelledBy);\n controlRef.current = element;\n return () => {\n /**\n * We get the latest attribute value because at the time that this cleanup fires,\n * the values from the closure may have changed.\n */\n const ariaLabelledBy = getAriaLabel()?.replace(id, '');\n if (ariaLabelledBy === '') {\n element.removeAttribute('aria-labelledby');\n } else if (ariaLabelledBy) {\n element.setAttribute('aria-labelledby', ariaLabelledBy);\n }\n };\n }\n }\n }, [id, htmlFor]);\n\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <Primitive.span\n role=\"label\"\n id={id}\n {...labelProps}\n ref={composedRefs}\n onMouseDown={(event) => {\n props.onMouseDown?.(event);\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) event.preventDefault();\n }}\n onClick={(event) => {\n props.onClick?.(event);\n if (!controlRef.current || event.defaultPrevented) return;\n const isClickingControl = controlRef.current.contains(event.target as Node);\n // Ensure event was generated by a user action\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted\n const isUserClick = event.isTrusted === true;\n /**\n * When a label is wrapped around the control it labels, we trigger the appropriate events\n * on the control when the label is clicked. We do nothing if the user is already clicking the\n * control inside the label.\n */\n if (!isClickingControl && isUserClick) {\n controlRef.current.click();\n controlRef.current.focus();\n }\n }}\n />\n </LabelProvider>\n );\n});\n\nLabel.displayName = NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst useLabelContext = (element?: HTMLElement | null) => {\n const context = useLabelContextImpl('LabelConsumer');\n const { controlRef } = context;\n\n React.useEffect(() => {\n if (element) controlRef.current = element;\n }, [element, controlRef]);\n\n return context.id;\n};\n\nconst Root = Label;\n\nexport {\n Label,\n //\n Root,\n //\n useLabelContext,\n};\nexport type { LabelProps };\n"],"names":["React","createContext","useComposedRefs","Primitive","useId","NAME","LabelProvider","useLabelContextImpl","id","undefined","controlRef","current","Label","forwardRef","props","forwardedRef","htmlFor","idProp","labelProps","useRef","ref","composedRefs","useEffect","element","document","getElementById","label","getAriaLabel","getAttribute","ariaLabelledBy","filter","Boolean","join","setAttribute","replace","removeAttribute","event","onMouseDown","defaultPrevented","detail","preventDefault","onClick","isClickingControl","contains","target","isUserClick","isTrusted","click","focus","useLabelContext","context","Root"],"version":3,"file":"index.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-label",
3
- "version": "0.1.6-rc.2",
3
+ "version": "0.1.6-rc.5",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -17,10 +17,10 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/runtime": "^7.13.10",
20
- "@radix-ui/react-compose-refs": "0.1.1-rc.2",
21
- "@radix-ui/react-context": "0.1.2-rc.2",
22
- "@radix-ui/react-id": "0.1.6-rc.2",
23
- "@radix-ui/react-primitive": "0.1.5-rc.2"
20
+ "@radix-ui/react-compose-refs": "0.1.1-rc.5",
21
+ "@radix-ui/react-context": "0.1.2-rc.5",
22
+ "@radix-ui/react-id": "0.1.6-rc.5",
23
+ "@radix-ui/react-primitive": "0.1.5-rc.5"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": "^16.8 || ^17.0 || ^18.0"