@radix-ui/react-label 1.0.0 → 2.0.0-rc.1

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.ts CHANGED
@@ -1,12 +1,10 @@
1
1
  import * as React from "react";
2
2
  import * as Radix from "@radix-ui/react-primitive";
3
3
  import { Primitive } from "@radix-ui/react-primitive";
4
- type PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;
5
- export interface LabelProps extends PrimitiveSpanProps {
6
- htmlFor?: string;
4
+ type PrimitiveLabelProps = Radix.ComponentPropsWithoutRef<typeof Primitive.label>;
5
+ export interface LabelProps extends PrimitiveLabelProps {
7
6
  }
8
- export const Label: React.ForwardRefExoticComponent<LabelProps & React.RefAttributes<HTMLSpanElement>>;
9
- export const useLabelContext: (element?: HTMLElement | null | undefined) => string | undefined;
10
- export const Root: React.ForwardRefExoticComponent<LabelProps & React.RefAttributes<HTMLSpanElement>>;
7
+ export const Label: React.ForwardRefExoticComponent<LabelProps & React.RefAttributes<HTMLLabelElement>>;
8
+ export const Root: React.ForwardRefExoticComponent<LabelProps & React.RefAttributes<HTMLLabelElement>>;
11
9
 
12
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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 {\n Label,\n //\n Root,\n //\n useLabelContext,\n} from './Label';\nexport type { LabelProps } from './Label';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
1
+ {"mappings":";;;AAYA,2BAA2B,MAAM,wBAAwB,CAAC,OAAO,UAAU,KAAK,CAAC,CAAC;AAClF,2BAAqB,SAAQ,mBAAmB;CAAG;AAEnD,OAAA,MAAM,0FAYJ,CAAC;AAMH,OAAA,MAAM,yFAAY,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 {\n Label,\n //\n Root,\n} from './Label';\nexport type { LabelProps } from './Label';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.js CHANGED
@@ -1,9 +1,6 @@
1
1
  var $RyX6d$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
2
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
3
  var $RyX6d$radixuireactprimitive = require("@radix-ui/react-primitive");
6
- var $RyX6d$radixuireactid = require("@radix-ui/react-id");
7
4
 
8
5
  function $parcel$export(e, n, v, s) {
9
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
@@ -14,102 +11,26 @@ function $parcel$interopDefault(a) {
14
11
 
15
12
  $parcel$export(module.exports, "Label", () => $2583d9c3eccdd4e2$export$b04be29aa201d4f5);
16
13
  $parcel$export(module.exports, "Root", () => $2583d9c3eccdd4e2$export$be92b6f5f03c0fe9);
17
- $parcel$export(module.exports, "useLabelContext", () => $2583d9c3eccdd4e2$export$feddbbf47baabdb9);
18
-
19
-
20
-
21
14
 
22
15
 
23
16
 
24
17
  /* -------------------------------------------------------------------------------------------------
25
18
  * Label
26
19
  * -----------------------------------------------------------------------------------------------*/ const $2583d9c3eccdd4e2$var$NAME = 'Label';
27
- const [$2583d9c3eccdd4e2$var$LabelProvider, $2583d9c3eccdd4e2$var$useLabelContextImpl] = $RyX6d$radixuireactcontext.createContext($2583d9c3eccdd4e2$var$NAME, {
28
- id: undefined,
29
- controlRef: {
30
- current: null
31
- }
32
- });
33
20
  const $2583d9c3eccdd4e2$export$b04be29aa201d4f5 = /*#__PURE__*/ $RyX6d$react.forwardRef((props, forwardedRef)=>{
34
- const { htmlFor: htmlFor , id: idProp , ...labelProps } = props;
35
- const controlRef = $RyX6d$react.useRef(null);
36
- const ref = $RyX6d$react.useRef(null);
37
- const composedRefs = $RyX6d$radixuireactcomposerefs.useComposedRefs(forwardedRef, ref);
38
- const id = $RyX6d$radixuireactid.useId(idProp);
39
- $RyX6d$react.useEffect(()=>{
40
- if (htmlFor) {
41
- const element = document.getElementById(htmlFor);
42
- const label = ref.current;
43
- if (label && element) {
44
- const getAriaLabel = ()=>element.getAttribute('aria-labelledby')
45
- ;
46
- const ariaLabelledBy1 = [
47
- id,
48
- getAriaLabel()
49
- ].filter(Boolean).join(' ');
50
- element.setAttribute('aria-labelledby', ariaLabelledBy1);
51
- controlRef.current = element;
52
- return ()=>{
53
- var _getAriaLabel;
54
- /**
55
- * We get the latest attribute value because at the time that this cleanup fires,
56
- * the values from the closure may have changed.
57
- */ const ariaLabelledBy = (_getAriaLabel = getAriaLabel()) === null || _getAriaLabel === void 0 ? void 0 : _getAriaLabel.replace(id, '');
58
- if (ariaLabelledBy === '') element.removeAttribute('aria-labelledby');
59
- else if (ariaLabelledBy) element.setAttribute('aria-labelledby', ariaLabelledBy);
60
- };
61
- }
62
- }
63
- }, [
64
- id,
65
- htmlFor
66
- ]);
67
- return /*#__PURE__*/ $RyX6d$react.createElement($2583d9c3eccdd4e2$var$LabelProvider, {
68
- id: id,
69
- controlRef: controlRef
70
- }, /*#__PURE__*/ $RyX6d$react.createElement($RyX6d$radixuireactprimitive.Primitive.span, ($parcel$interopDefault($RyX6d$babelruntimehelpersextends))({
71
- role: "label",
72
- id: id
73
- }, labelProps, {
74
- ref: composedRefs,
21
+ return /*#__PURE__*/ $RyX6d$react.createElement($RyX6d$radixuireactprimitive.Primitive.label, ($parcel$interopDefault($RyX6d$babelruntimehelpersextends))({}, props, {
22
+ ref: forwardedRef,
75
23
  onMouseDown: (event)=>{
76
24
  var _props$onMouseDown;
77
25
  (_props$onMouseDown = props.onMouseDown) === null || _props$onMouseDown === void 0 || _props$onMouseDown.call(props, event); // prevent text selection when double clicking label
78
26
  if (!event.defaultPrevented && event.detail > 1) event.preventDefault();
79
- },
80
- onClick: (event)=>{
81
- var _props$onClick;
82
- (_props$onClick = props.onClick) === null || _props$onClick === void 0 || _props$onClick.call(props, event);
83
- if (!controlRef.current || event.defaultPrevented) return;
84
- const isClickingControl = controlRef.current.contains(event.target); // Ensure event was generated by a user action
85
- // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted
86
- const isUserClick = event.isTrusted === true;
87
- /**
88
- * When a label is wrapped around the control it labels, we trigger the appropriate events
89
- * on the control when the label is clicked. We do nothing if the user is already clicking the
90
- * control inside the label.
91
- */ if (!isClickingControl && isUserClick) {
92
- controlRef.current.click();
93
- controlRef.current.focus();
94
- }
95
27
  }
96
- })));
28
+ }));
97
29
  });
98
30
  /*#__PURE__*/ Object.assign($2583d9c3eccdd4e2$export$b04be29aa201d4f5, {
99
31
  displayName: $2583d9c3eccdd4e2$var$NAME
100
32
  });
101
- /* -----------------------------------------------------------------------------------------------*/ const $2583d9c3eccdd4e2$export$feddbbf47baabdb9 = (element)=>{
102
- const context = $2583d9c3eccdd4e2$var$useLabelContextImpl('LabelConsumer');
103
- const { controlRef: controlRef } = context;
104
- $RyX6d$react.useEffect(()=>{
105
- if (element) controlRef.current = element;
106
- }, [
107
- element,
108
- controlRef
109
- ]);
110
- return context.id;
111
- };
112
- const $2583d9c3eccdd4e2$export$be92b6f5f03c0fe9 = $2583d9c3eccdd4e2$export$b04be29aa201d4f5;
33
+ /* -----------------------------------------------------------------------------------------------*/ const $2583d9c3eccdd4e2$export$be92b6f5f03c0fe9 = $2583d9c3eccdd4e2$export$b04be29aa201d4f5;
113
34
 
114
35
 
115
36
 
package/dist/index.js.map CHANGED
@@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ARF,AASC;AAED,MAAMV,yCAAI,GAAGD,yCAAb,AAAA;;AD3GA","sources":["packages/react/label/src/index.ts","packages/react/label/src/Label.tsx"],"sourcesContent":["export {\n Label,\n //\n Root,\n //\n useLabelContext,\n} from './Label';\nexport type { LabelProps } 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":["Label","Root","useLabelContext","React","createContext","useComposedRefs","Primitive","useId","NAME","LabelProvider","useLabelContextImpl","id","undefined","controlRef","current","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","context"],"version":3,"file":"index.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;A;;;ACKA;;oGAEA,CAEA,MAAMI,0BAAI,GAAG,OAAb,AAAA;AAMA,MAAMJ,yCAAK,GAAA,aAAGE,CAAAA,uBAAA,CAA2C,CAACI,KAAD,EAAQC,YAAR,GAAyB;IAChF,OAAA,aACE,CAAA,0BAAA,CAAC,sCAAD,CAAW,KAAX,EAAA,2DAAA,CAAA,EAAA,EACMD,KADN,EADF;QAGI,GAAG,EAAEC,YAFP;QAGE,WAAW,EAAGC,CAAAA,KAAD,GAAW;YAAA,IAAA,kBAAA,AAAA;YACtB,CAAA,kBAAA,GAAAF,KAAK,CAACG,WAAN,CAAA,KAAA,IAAA,IAAA,kBAAA,KAAA,KAAA,CAAA,IAAA,kBAAA,CAAA,IAAA,CAAAH,KAAK,EAAeE,KAAf,CAAL,CADsB,CAEtB,oDADA;YAEA,IAAI,CAACA,KAAK,CAACE,gBAAP,IAA2BF,KAAK,CAACG,MAAN,GAAe,CAA9C,EAAiDH,KAAK,CAACI,cAAN,EAAjD,CAAA;SACD;KAPH,CAAA,CADF,CACE;CAFU,CAAd,AAYC;AAED,aAAA,CAAA,MAAA,CAAA,MAAA,CAAA,yCAAA,EAAA;IAAA,WAAA,EAAA,0BAAA;CAAA,CAAA,CAAA;AAEA,oGAAA,CAEA,MAAMX,yCAAI,GAAGD,yCAAb,AAAA;;ADjCA","sources":["packages/react/label/src/index.ts","packages/react/label/src/Label.tsx"],"sourcesContent":["export {\n Label,\n //\n Root,\n} from './Label';\nexport type { LabelProps } from './Label';\n","import * as React from 'react';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * Label\n * -----------------------------------------------------------------------------------------------*/\n\nconst NAME = 'Label';\n\ntype LabelElement = React.ElementRef<typeof Primitive.label>;\ntype PrimitiveLabelProps = Radix.ComponentPropsWithoutRef<typeof Primitive.label>;\ninterface LabelProps extends PrimitiveLabelProps {}\n\nconst Label = React.forwardRef<LabelElement, LabelProps>((props, forwardedRef) => {\n return (\n <Primitive.label\n {...props}\n ref={forwardedRef}\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 />\n );\n});\n\nLabel.displayName = NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Label;\n\nexport {\n Label,\n //\n Root,\n};\nexport type { LabelProps };\n"],"names":["Label","Root","React","Primitive","NAME","forwardRef","props","forwardedRef","event","onMouseDown","defaultPrevented","detail","preventDefault"],"version":3,"file":"index.js.map"}
@@ -1,12 +1,6 @@
1
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";
2
+ import {forwardRef as $7V4JZ$forwardRef, createElement as $7V4JZ$createElement} from "react";
5
3
  import {Primitive as $7V4JZ$Primitive} from "@radix-ui/react-primitive";
6
- import {useId as $7V4JZ$useId} from "@radix-ui/react-id";
7
-
8
-
9
-
10
4
 
11
5
 
12
6
 
@@ -14,95 +8,23 @@ import {useId as $7V4JZ$useId} from "@radix-ui/react-id";
14
8
  /* -------------------------------------------------------------------------------------------------
15
9
  * Label
16
10
  * -----------------------------------------------------------------------------------------------*/ const $b73a6c6685e72184$var$NAME = 'Label';
17
- const [$b73a6c6685e72184$var$LabelProvider, $b73a6c6685e72184$var$useLabelContextImpl] = $7V4JZ$createContext($b73a6c6685e72184$var$NAME, {
18
- id: undefined,
19
- controlRef: {
20
- current: null
21
- }
22
- });
23
11
  const $b73a6c6685e72184$export$b04be29aa201d4f5 = /*#__PURE__*/ $7V4JZ$forwardRef((props, forwardedRef)=>{
24
- const { htmlFor: htmlFor , id: idProp , ...labelProps } = props;
25
- const controlRef = $7V4JZ$useRef(null);
26
- const ref = $7V4JZ$useRef(null);
27
- const composedRefs = $7V4JZ$useComposedRefs(forwardedRef, ref);
28
- const id = $7V4JZ$useId(idProp);
29
- $7V4JZ$useEffect(()=>{
30
- if (htmlFor) {
31
- const element = document.getElementById(htmlFor);
32
- const label = ref.current;
33
- if (label && element) {
34
- const getAriaLabel = ()=>element.getAttribute('aria-labelledby')
35
- ;
36
- const ariaLabelledBy1 = [
37
- id,
38
- getAriaLabel()
39
- ].filter(Boolean).join(' ');
40
- element.setAttribute('aria-labelledby', ariaLabelledBy1);
41
- controlRef.current = element;
42
- return ()=>{
43
- var _getAriaLabel;
44
- /**
45
- * We get the latest attribute value because at the time that this cleanup fires,
46
- * the values from the closure may have changed.
47
- */ const ariaLabelledBy = (_getAriaLabel = getAriaLabel()) === null || _getAriaLabel === void 0 ? void 0 : _getAriaLabel.replace(id, '');
48
- if (ariaLabelledBy === '') element.removeAttribute('aria-labelledby');
49
- else if (ariaLabelledBy) element.setAttribute('aria-labelledby', ariaLabelledBy);
50
- };
51
- }
52
- }
53
- }, [
54
- id,
55
- htmlFor
56
- ]);
57
- return /*#__PURE__*/ $7V4JZ$createElement($b73a6c6685e72184$var$LabelProvider, {
58
- id: id,
59
- controlRef: controlRef
60
- }, /*#__PURE__*/ $7V4JZ$createElement($7V4JZ$Primitive.span, $7V4JZ$babelruntimehelpersesmextends({
61
- role: "label",
62
- id: id
63
- }, labelProps, {
64
- ref: composedRefs,
12
+ return /*#__PURE__*/ $7V4JZ$createElement($7V4JZ$Primitive.label, $7V4JZ$babelruntimehelpersesmextends({}, props, {
13
+ ref: forwardedRef,
65
14
  onMouseDown: (event)=>{
66
15
  var _props$onMouseDown;
67
16
  (_props$onMouseDown = props.onMouseDown) === null || _props$onMouseDown === void 0 || _props$onMouseDown.call(props, event); // prevent text selection when double clicking label
68
17
  if (!event.defaultPrevented && event.detail > 1) event.preventDefault();
69
- },
70
- onClick: (event)=>{
71
- var _props$onClick;
72
- (_props$onClick = props.onClick) === null || _props$onClick === void 0 || _props$onClick.call(props, event);
73
- if (!controlRef.current || event.defaultPrevented) return;
74
- const isClickingControl = controlRef.current.contains(event.target); // Ensure event was generated by a user action
75
- // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted
76
- const isUserClick = event.isTrusted === true;
77
- /**
78
- * When a label is wrapped around the control it labels, we trigger the appropriate events
79
- * on the control when the label is clicked. We do nothing if the user is already clicking the
80
- * control inside the label.
81
- */ if (!isClickingControl && isUserClick) {
82
- controlRef.current.click();
83
- controlRef.current.focus();
84
- }
85
18
  }
86
- })));
19
+ }));
87
20
  });
88
21
  /*#__PURE__*/ Object.assign($b73a6c6685e72184$export$b04be29aa201d4f5, {
89
22
  displayName: $b73a6c6685e72184$var$NAME
90
23
  });
91
- /* -----------------------------------------------------------------------------------------------*/ const $b73a6c6685e72184$export$feddbbf47baabdb9 = (element)=>{
92
- const context = $b73a6c6685e72184$var$useLabelContextImpl('LabelConsumer');
93
- const { controlRef: controlRef } = context;
94
- $7V4JZ$useEffect(()=>{
95
- if (element) controlRef.current = element;
96
- }, [
97
- element,
98
- controlRef
99
- ]);
100
- return context.id;
101
- };
102
- const $b73a6c6685e72184$export$be92b6f5f03c0fe9 = $b73a6c6685e72184$export$b04be29aa201d4f5;
24
+ /* -----------------------------------------------------------------------------------------------*/ const $b73a6c6685e72184$export$be92b6f5f03c0fe9 = $b73a6c6685e72184$export$b04be29aa201d4f5;
103
25
 
104
26
 
105
27
 
106
28
 
107
- export {$b73a6c6685e72184$export$b04be29aa201d4f5 as Label, $b73a6c6685e72184$export$be92b6f5f03c0fe9 as Root, $b73a6c6685e72184$export$feddbbf47baabdb9 as useLabelContext};
29
+ export {$b73a6c6685e72184$export$b04be29aa201d4f5 as Label, $b73a6c6685e72184$export$be92b6f5f03c0fe9 as Root};
108
30
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;;;;A;;;;;;ACQA;;oGAEA,CAEA,MAAMQ,0B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src/Label.tsx"],"sourcesContent":["export {\n Label,\n //\n Root,\n //\n useLabelContext,\n} from './Label';\nexport type { LabelProps } 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":["Label","Root","useLabelContext","React","createContext","useComposedRefs","Primitive","useId","NAME","LabelProvider","useLabelContextImpl","id","undefined","controlRef","current","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","context"],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":";;;;A;;;ACKA;;oGAEA,CAEA,MAAMI,0BAAI,GAAG,OAAb,AAAA;AAMA,MAAMJ,yCAAK,GAAA,aAAGE,CAAAA,iBAAA,CAA2C,CAACI,KAAD,EAAQC,YAAR,GAAyB;IAChF,OAAA,aACE,CAAA,oBAAA,CAAC,gBAAD,CAAW,KAAX,EAAA,oCAAA,CAAA,EAAA,EACMD,KADN,EADF;QAGI,GAAG,EAAEC,YAFP;QAGE,WAAW,EAAGC,CAAAA,KAAD,GAAW;YAAA,IAAA,kBAAA,AAAA;YACtB,CAAA,kBAAA,GAAAF,KAAK,CAACG,WAAN,CAAA,KAAA,IAAA,IAAA,kBAAA,KAAA,KAAA,CAAA,IAAA,kBAAA,CAAA,IAAA,CAAAH,KAAK,EAAeE,KAAf,CAAL,CADsB,CAEtB,oDADA;YAEA,IAAI,CAACA,KAAK,CAACE,gBAAP,IAA2BF,KAAK,CAACG,MAAN,GAAe,CAA9C,EAAiDH,KAAK,CAACI,cAAN,EAAjD,CAAA;SACD;KAPH,CAAA,CADF,CACE;CAFU,CAAd,AAYC;AAED,aAAA,CAAA,MAAA,CAAA,MAAA,CAAA,yCAAA,EAAA;IAAA,WAAA,EAAA,0BAAA;CAAA,CAAA,CAAA;AAEA,oGAAA,CAEA,MAAMX,yCAAI,GAAGD,yCAAb,AAAA;;ADjCA","sources":["packages/react/label/src/index.ts","packages/react/label/src/Label.tsx"],"sourcesContent":["export {\n Label,\n //\n Root,\n} from './Label';\nexport type { LabelProps } from './Label';\n","import * as React from 'react';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * Label\n * -----------------------------------------------------------------------------------------------*/\n\nconst NAME = 'Label';\n\ntype LabelElement = React.ElementRef<typeof Primitive.label>;\ntype PrimitiveLabelProps = Radix.ComponentPropsWithoutRef<typeof Primitive.label>;\ninterface LabelProps extends PrimitiveLabelProps {}\n\nconst Label = React.forwardRef<LabelElement, LabelProps>((props, forwardedRef) => {\n return (\n <Primitive.label\n {...props}\n ref={forwardedRef}\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 />\n );\n});\n\nLabel.displayName = NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Label;\n\nexport {\n Label,\n //\n Root,\n};\nexport type { LabelProps };\n"],"names":["Label","Root","React","Primitive","NAME","forwardRef","props","forwardedRef","event","onMouseDown","defaultPrevented","detail","preventDefault"],"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": "1.0.0",
3
+ "version": "2.0.0-rc.1",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -17,10 +17,7 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/runtime": "^7.13.10",
20
- "@radix-ui/react-compose-refs": "1.0.0",
21
- "@radix-ui/react-context": "1.0.0",
22
- "@radix-ui/react-id": "1.0.0",
23
- "@radix-ui/react-primitive": "1.0.0"
20
+ "@radix-ui/react-primitive": "1.0.1-rc.1"
24
21
  },
25
22
  "peerDependencies": {
26
23
  "react": "^16.8 || ^17.0 || ^18.0",
@@ -33,5 +30,6 @@
33
30
  },
34
31
  "bugs": {
35
32
  "url": "https://github.com/radix-ui/primitives/issues"
36
- }
33
+ },
34
+ "stableVersion": "1.0.0"
37
35
  }