@tamagui/label 1.13.3 → 1.13.4
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/cjs/Label.js +1 -174
- package/dist/cjs/Label.js.map +2 -2
- package/dist/cjs/index.js +1 -18
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/Label.js +1 -143
- package/dist/esm/Label.js.map +2 -2
- package/dist/esm/Label.mjs +1 -143
- package/dist/esm/Label.mjs.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/jsx/Label.js +1 -136
- package/dist/jsx/Label.js.map +2 -2
- package/dist/jsx/Label.mjs +1 -136
- package/dist/jsx/Label.mjs.map +2 -2
- package/dist/jsx/index.js +1 -1
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +1 -1
- package/dist/jsx/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/cjs/Label.js
CHANGED
|
@@ -1,175 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var Label_exports = {};
|
|
30
|
-
__export(Label_exports, {
|
|
31
|
-
Label: () => Label,
|
|
32
|
-
LabelFrame: () => LabelFrame,
|
|
33
|
-
useLabelContext: () => useLabelContext
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(Label_exports);
|
|
36
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
37
|
-
var import_compose_refs = require("@tamagui/compose-refs");
|
|
38
|
-
var import_create_context = require("@tamagui/create-context");
|
|
39
|
-
var import_focusable = require("@tamagui/focusable");
|
|
40
|
-
var import_get_button_sized = require("@tamagui/get-button-sized");
|
|
41
|
-
var import_get_font_sized = require("@tamagui/get-font-sized");
|
|
42
|
-
var import_text = require("@tamagui/text");
|
|
43
|
-
var import_web = require("@tamagui/web");
|
|
44
|
-
var React = __toESM(require("react"));
|
|
45
|
-
const NAME = "Label";
|
|
46
|
-
const [LabelProvider, useLabelContextImpl] = (0, import_create_context.createContext)(NAME, {
|
|
47
|
-
id: void 0,
|
|
48
|
-
controlRef: { current: null }
|
|
49
|
-
});
|
|
50
|
-
const LabelFrame = (0, import_web.styled)(import_text.SizableText, {
|
|
51
|
-
name: "Label",
|
|
52
|
-
tag: "label",
|
|
53
|
-
variants: {
|
|
54
|
-
unstyled: {
|
|
55
|
-
false: {
|
|
56
|
-
size: "$true",
|
|
57
|
-
color: "$color",
|
|
58
|
-
backgroundColor: "transparent",
|
|
59
|
-
display: "flex",
|
|
60
|
-
alignItems: "center",
|
|
61
|
-
userSelect: "none",
|
|
62
|
-
cursor: "default",
|
|
63
|
-
pressStyle: {
|
|
64
|
-
color: "$colorPress"
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
size: {
|
|
69
|
-
"...size": (val, extras) => {
|
|
70
|
-
const buttonStyle = (0, import_get_button_sized.getButtonSized)(val, extras);
|
|
71
|
-
return {
|
|
72
|
-
...(0, import_get_font_sized.getFontSized)(val, extras),
|
|
73
|
-
height: buttonStyle.height,
|
|
74
|
-
lineHeight: buttonStyle.height
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
defaultVariants: {
|
|
80
|
-
unstyled: false
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
const LabelComponent = React.forwardRef(
|
|
84
|
-
(props, forwardedRef) => {
|
|
85
|
-
const { htmlFor, id: idProp, ...labelProps } = props;
|
|
86
|
-
const controlRef = React.useRef(null);
|
|
87
|
-
const ref = React.useRef(null);
|
|
88
|
-
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
89
|
-
const backupId = (0, import_web.useId)();
|
|
90
|
-
const id = idProp ?? backupId;
|
|
91
|
-
if (import_web.isWeb) {
|
|
92
|
-
React.useEffect(() => {
|
|
93
|
-
if (htmlFor) {
|
|
94
|
-
const element = document.getElementById(htmlFor);
|
|
95
|
-
const label = ref.current;
|
|
96
|
-
if (label && element) {
|
|
97
|
-
const getAriaLabel = () => element.getAttribute("aria-labelledby");
|
|
98
|
-
const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(" ");
|
|
99
|
-
element.setAttribute("aria-labelledby", ariaLabelledBy);
|
|
100
|
-
controlRef.current = element;
|
|
101
|
-
return () => {
|
|
102
|
-
var _a;
|
|
103
|
-
if (!id)
|
|
104
|
-
return;
|
|
105
|
-
const ariaLabelledBy2 = (_a = getAriaLabel()) == null ? void 0 : _a.replace(id, "");
|
|
106
|
-
if (ariaLabelledBy2 === "") {
|
|
107
|
-
element.removeAttribute("aria-labelledby");
|
|
108
|
-
} else if (ariaLabelledBy2) {
|
|
109
|
-
element.setAttribute("aria-labelledby", ariaLabelledBy2);
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}, [id, htmlFor]);
|
|
115
|
-
}
|
|
116
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LabelProvider, { id, controlRef, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
117
|
-
LabelFrame,
|
|
118
|
-
{
|
|
119
|
-
role: "heading",
|
|
120
|
-
id,
|
|
121
|
-
htmlFor,
|
|
122
|
-
...labelProps,
|
|
123
|
-
ref: composedRefs,
|
|
124
|
-
onMouseDown: (event) => {
|
|
125
|
-
var _a;
|
|
126
|
-
(_a = props.onMouseDown) == null ? void 0 : _a.call(props, event);
|
|
127
|
-
if (!event.defaultPrevented && event.detail > 1) {
|
|
128
|
-
event.preventDefault();
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
onPress: (event) => {
|
|
132
|
-
var _a;
|
|
133
|
-
(_a = props.onPress) == null ? void 0 : _a.call(props, event);
|
|
134
|
-
if (import_web.isWeb) {
|
|
135
|
-
if (htmlFor || !controlRef.current || event.defaultPrevented)
|
|
136
|
-
return;
|
|
137
|
-
const isClickingControl = controlRef.current.contains(
|
|
138
|
-
event.target
|
|
139
|
-
);
|
|
140
|
-
const isUserClick = event.isTrusted === true;
|
|
141
|
-
if (!isClickingControl && isUserClick) {
|
|
142
|
-
controlRef.current.click();
|
|
143
|
-
controlRef.current.focus();
|
|
144
|
-
}
|
|
145
|
-
} else {
|
|
146
|
-
if (props.htmlFor) {
|
|
147
|
-
(0, import_focusable.focusFocusable)(props.htmlFor);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
) });
|
|
153
|
-
}
|
|
154
|
-
);
|
|
155
|
-
LabelComponent.displayName = NAME;
|
|
156
|
-
const Label = LabelFrame.extractable((0, import_web.themeable)(LabelComponent), {
|
|
157
|
-
neverFlatten: true
|
|
158
|
-
});
|
|
159
|
-
const useLabelContext = (element) => {
|
|
160
|
-
const context = useLabelContextImpl("LabelConsumer");
|
|
161
|
-
const { controlRef } = context;
|
|
162
|
-
React.useEffect(() => {
|
|
163
|
-
if (element)
|
|
164
|
-
controlRef.current = element;
|
|
165
|
-
}, [element, controlRef]);
|
|
166
|
-
return context.id;
|
|
167
|
-
};
|
|
168
|
-
const Root = Label;
|
|
169
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
170
|
-
0 && (module.exports = {
|
|
171
|
-
Label,
|
|
172
|
-
LabelFrame,
|
|
173
|
-
useLabelContext
|
|
174
|
-
});
|
|
1
|
+
"use strict";var T=Object.create;var b=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var V=(e,o)=>{for(var t in o)b(e,t,{get:o[t],enumerable:!0})},h=(e,o,t,u)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of w(o))!I.call(e,n)&&n!==t&&b(e,n,{get:()=>o[n],enumerable:!(u=k(o,n))||u.enumerable});return e};var D=(e,o,t)=>(t=e!=null?T(H(e)):{},h(o||!e||!e.__esModule?b(t,"default",{value:e,enumerable:!0}):t,e)),N=e=>h(b({},"__esModule",{value:!0}),e);var j={};V(j,{Label:()=>A,LabelFrame:()=>L,useLabelContext:()=>G});module.exports=N(j);var y=require("react/jsx-runtime"),p=require("@tamagui/compose-refs"),x=require("@tamagui/create-context"),F=require("@tamagui/focusable"),E=require("@tamagui/get-button-sized"),M=require("@tamagui/get-font-sized"),z=require("@tamagui/text"),l=require("@tamagui/web"),c=D(require("react"));const C="Label",[W,$]=(0,x.createContext)(C,{id:void 0,controlRef:{current:null}}),L=(0,l.styled)(z.SizableText,{name:"Label",tag:"label",variants:{unstyled:{false:{size:"$true",color:"$color",backgroundColor:"transparent",display:"flex",alignItems:"center",userSelect:"none",cursor:"default",pressStyle:{color:"$colorPress"}}},size:{"...size":(e,o)=>{const t=(0,E.getButtonSized)(e,o);return{...(0,M.getFontSized)(e,o),height:t.height,lineHeight:t.height}}}},defaultVariants:{unstyled:!1}}),P=c.forwardRef((e,o)=>{const{htmlFor:t,id:u,...n}=e,a=c.useRef(null),g=c.useRef(null),B=(0,p.useComposedRefs)(o,g),S=(0,l.useId)(),s=u??S;return l.isWeb&&c.useEffect(()=>{if(t){const r=document.getElementById(t);if(g.current&&r){const f=()=>r.getAttribute("aria-labelledby"),d=[s,f()].filter(Boolean).join(" ");return r.setAttribute("aria-labelledby",d),a.current=r,()=>{var R;if(!s)return;const m=(R=f())==null?void 0:R.replace(s,"");m===""?r.removeAttribute("aria-labelledby"):m&&r.setAttribute("aria-labelledby",m)}}}},[s,t]),(0,y.jsx)(W,{id:s,controlRef:a,children:(0,y.jsx)(L,{role:"heading",id:s,htmlFor:t,...n,ref:B,onMouseDown:r=>{var i;(i=e.onMouseDown)==null||i.call(e,r),!r.defaultPrevented&&r.detail>1&&r.preventDefault()},onPress:r=>{var i;if((i=e.onPress)==null||i.call(e,r),l.isWeb){if(t||!a.current||r.defaultPrevented)return;const f=a.current.contains(r.target),d=r.isTrusted===!0;!f&&d&&(a.current.click(),a.current.focus())}else e.htmlFor&&(0,F.focusFocusable)(e.htmlFor)}})})});P.displayName=C;const A=L.extractable((0,l.themeable)(P),{neverFlatten:!0}),G=e=>{const o=$("LabelConsumer"),{controlRef:t}=o;return c.useEffect(()=>{e&&(t.current=e)},[e,t]),o.id},K=A;0&&(module.exports={Label,LabelFrame,useLabelContext});
|
|
175
2
|
//# sourceMappingURL=Label.js.map
|
package/dist/cjs/Label.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Label.tsx"],
|
|
4
4
|
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n} from '@tamagui/web'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n color: '$color',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n },\n },\n\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\n },\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\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 if (!id) return\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\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n role=\"heading\"\n id={id}\n // @ts-ignore\n htmlFor={htmlFor}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (htmlFor || !controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\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 } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const 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"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["ariaLabelledBy"]
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,EAAA,eAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAL,GA6GQ,IAAAM,EAAA,6BA7GRC,EAAgC,iCAChCC,EAA8B,mCAC9BC,EAA+B,8BAC/BC,EAA+B,qCAC/BC,EAA6B,mCAC7BC,EAA4B,yBAC5BC,EAOO,wBACPC,EAAuB,oBAGvB,MAAMC,EAAO,QAOP,CAACC,EAAeC,CAAmB,KAAI,iBAAiCF,EAAM,CAClF,GAAI,OACJ,WAAY,CAAE,QAAS,IAAK,CAC9B,CAAC,EAEYZ,KAAa,UAAO,cAAa,CAC5C,KAAM,QACN,IAAK,QAEL,SAAU,CACR,SAAU,CACR,MAAO,CACL,KAAM,QACN,MAAO,SACP,gBAAiB,cACjB,QAAS,OACT,WAAY,SACZ,WAAY,OACZ,OAAQ,UACR,WAAY,CACV,MAAO,aACT,CACF,CACF,EAEA,KAAM,CACJ,UAAW,CAACe,EAAKC,IAAW,CAC1B,MAAMC,KAAc,kBAAeF,EAAKC,CAAM,EAC9C,MAAO,CACL,MAAG,gBAAaD,EAAKC,CAAM,EAC3B,OAAQC,EAAY,OACpB,WAAYA,EAAY,MAC1B,CACF,CACF,CACF,EAEA,gBAAiB,CACf,SAAU,EACZ,CACF,CAAC,EAMKC,EAAiBP,EAAM,WAC3B,CAACQ,EAAOC,IAAiB,CACvB,KAAM,CAAE,QAAAC,EAAS,GAAIC,EAAQ,GAAGC,CAAW,EAAIJ,EACzCK,EAAab,EAAM,OAA2B,IAAI,EAClDc,EAAMd,EAAM,OAAY,IAAI,EAC5Be,KAAe,mBAAgBN,EAAcK,CAAG,EAChDE,KAAW,SAAM,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AeA,EAAM,OAAO,CAGlC,EACF,EACF,CAEJ,CACF,EAEAD,EAAe,YAAcN,EAEtB,MAAMb,EACXC,EAAW,eAAY,aAAUkB,CAAqB,EAAU,CAC9D,aAAc,EAChB,CAAC,EAEUjB,EAAmB4B,GAAiC,CAC/D,MAAMO,EAAUtB,EAAoB,eAAe,EAC7C,CAAE,WAAAU,CAAW,EAAIY,EAEvB,OAAAzB,EAAM,UAAU,IAAM,CAChBkB,IAASL,EAAW,QAAUK,EACpC,EAAG,CAACA,EAASL,CAAU,CAAC,EAEjBY,EAAQ,EACjB,EAEMC,EAAOtC",
|
|
6
|
+
"names": ["Label_exports", "__export", "Label", "LabelFrame", "useLabelContext", "__toCommonJS", "import_jsx_runtime", "import_compose_refs", "import_create_context", "import_focusable", "import_get_button_sized", "import_get_font_sized", "import_text", "import_web", "React", "NAME", "LabelProvider", "useLabelContextImpl", "val", "extras", "buttonStyle", "LabelComponent", "props", "forwardedRef", "htmlFor", "idProp", "labelProps", "controlRef", "ref", "composedRefs", "backupId", "id", "element", "getAriaLabel", "ariaLabelledBy", "_a", "event", "isClickingControl", "isUserClick", "context", "Root"]
|
|
7
7
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var src_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(src_exports);
|
|
18
|
-
__reExport(src_exports, require("./Label"), module.exports);
|
|
1
|
+
"use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(r,o,f,x)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of c(o))!d.call(r,e)&&e!==f&&a(r,e,{get:()=>o[e],enumerable:!(x=b(o,e))||x.enumerable});return r},t=(r,o,f)=>(p(r,o,"default"),f&&p(f,o,"default"));var g=r=>p(a({},"__esModule",{value:!0}),r);var m={};module.exports=g(m);t(m,require("./Label"),module.exports);
|
|
19
2
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["export * from './Label'\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "iaAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAAAE,EAAAF,EAAc,mBAAd",
|
|
6
|
+
"names": ["src_exports", "__toCommonJS", "__reExport"]
|
|
7
7
|
}
|
package/dist/esm/Label.js
CHANGED
|
@@ -1,144 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
3
|
-
import { createContext } from "@tamagui/create-context";
|
|
4
|
-
import { focusFocusable } from "@tamagui/focusable";
|
|
5
|
-
import { getButtonSized } from "@tamagui/get-button-sized";
|
|
6
|
-
import { getFontSized } from "@tamagui/get-font-sized";
|
|
7
|
-
import { SizableText } from "@tamagui/text";
|
|
8
|
-
import {
|
|
9
|
-
isWeb,
|
|
10
|
-
styled,
|
|
11
|
-
themeable,
|
|
12
|
-
useId
|
|
13
|
-
} from "@tamagui/web";
|
|
14
|
-
import * as React from "react";
|
|
15
|
-
const NAME = "Label";
|
|
16
|
-
const [LabelProvider, useLabelContextImpl] = createContext(NAME, {
|
|
17
|
-
id: void 0,
|
|
18
|
-
controlRef: { current: null }
|
|
19
|
-
});
|
|
20
|
-
const LabelFrame = styled(SizableText, {
|
|
21
|
-
name: "Label",
|
|
22
|
-
tag: "label",
|
|
23
|
-
variants: {
|
|
24
|
-
unstyled: {
|
|
25
|
-
false: {
|
|
26
|
-
size: "$true",
|
|
27
|
-
color: "$color",
|
|
28
|
-
backgroundColor: "transparent",
|
|
29
|
-
display: "flex",
|
|
30
|
-
alignItems: "center",
|
|
31
|
-
userSelect: "none",
|
|
32
|
-
cursor: "default",
|
|
33
|
-
pressStyle: {
|
|
34
|
-
color: "$colorPress"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
size: {
|
|
39
|
-
"...size": (val, extras) => {
|
|
40
|
-
const buttonStyle = getButtonSized(val, extras);
|
|
41
|
-
return {
|
|
42
|
-
...getFontSized(val, extras),
|
|
43
|
-
height: buttonStyle.height,
|
|
44
|
-
lineHeight: buttonStyle.height
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
defaultVariants: {
|
|
50
|
-
unstyled: false
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const LabelComponent = React.forwardRef(
|
|
54
|
-
(props, forwardedRef) => {
|
|
55
|
-
const { htmlFor, id: idProp, ...labelProps } = props;
|
|
56
|
-
const controlRef = React.useRef(null);
|
|
57
|
-
const ref = React.useRef(null);
|
|
58
|
-
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
59
|
-
const backupId = useId();
|
|
60
|
-
const id = idProp ?? backupId;
|
|
61
|
-
if (isWeb) {
|
|
62
|
-
React.useEffect(() => {
|
|
63
|
-
if (htmlFor) {
|
|
64
|
-
const element = document.getElementById(htmlFor);
|
|
65
|
-
const label = ref.current;
|
|
66
|
-
if (label && element) {
|
|
67
|
-
const getAriaLabel = () => element.getAttribute("aria-labelledby");
|
|
68
|
-
const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(" ");
|
|
69
|
-
element.setAttribute("aria-labelledby", ariaLabelledBy);
|
|
70
|
-
controlRef.current = element;
|
|
71
|
-
return () => {
|
|
72
|
-
var _a;
|
|
73
|
-
if (!id)
|
|
74
|
-
return;
|
|
75
|
-
const ariaLabelledBy2 = (_a = getAriaLabel()) == null ? void 0 : _a.replace(id, "");
|
|
76
|
-
if (ariaLabelledBy2 === "") {
|
|
77
|
-
element.removeAttribute("aria-labelledby");
|
|
78
|
-
} else if (ariaLabelledBy2) {
|
|
79
|
-
element.setAttribute("aria-labelledby", ariaLabelledBy2);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}, [id, htmlFor]);
|
|
85
|
-
}
|
|
86
|
-
return /* @__PURE__ */ jsx(LabelProvider, { id, controlRef, children: /* @__PURE__ */ jsx(
|
|
87
|
-
LabelFrame,
|
|
88
|
-
{
|
|
89
|
-
role: "heading",
|
|
90
|
-
id,
|
|
91
|
-
htmlFor,
|
|
92
|
-
...labelProps,
|
|
93
|
-
ref: composedRefs,
|
|
94
|
-
onMouseDown: (event) => {
|
|
95
|
-
var _a;
|
|
96
|
-
(_a = props.onMouseDown) == null ? void 0 : _a.call(props, event);
|
|
97
|
-
if (!event.defaultPrevented && event.detail > 1) {
|
|
98
|
-
event.preventDefault();
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
onPress: (event) => {
|
|
102
|
-
var _a;
|
|
103
|
-
(_a = props.onPress) == null ? void 0 : _a.call(props, event);
|
|
104
|
-
if (isWeb) {
|
|
105
|
-
if (htmlFor || !controlRef.current || event.defaultPrevented)
|
|
106
|
-
return;
|
|
107
|
-
const isClickingControl = controlRef.current.contains(
|
|
108
|
-
event.target
|
|
109
|
-
);
|
|
110
|
-
const isUserClick = event.isTrusted === true;
|
|
111
|
-
if (!isClickingControl && isUserClick) {
|
|
112
|
-
controlRef.current.click();
|
|
113
|
-
controlRef.current.focus();
|
|
114
|
-
}
|
|
115
|
-
} else {
|
|
116
|
-
if (props.htmlFor) {
|
|
117
|
-
focusFocusable(props.htmlFor);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
) });
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
LabelComponent.displayName = NAME;
|
|
126
|
-
const Label = LabelFrame.extractable(themeable(LabelComponent), {
|
|
127
|
-
neverFlatten: true
|
|
128
|
-
});
|
|
129
|
-
const useLabelContext = (element) => {
|
|
130
|
-
const context = useLabelContextImpl("LabelConsumer");
|
|
131
|
-
const { controlRef } = context;
|
|
132
|
-
React.useEffect(() => {
|
|
133
|
-
if (element)
|
|
134
|
-
controlRef.current = element;
|
|
135
|
-
}, [element, controlRef]);
|
|
136
|
-
return context.id;
|
|
137
|
-
};
|
|
138
|
-
const Root = Label;
|
|
139
|
-
export {
|
|
140
|
-
Label,
|
|
141
|
-
LabelFrame,
|
|
142
|
-
useLabelContext
|
|
143
|
-
};
|
|
1
|
+
import{jsx as g}from"react/jsx-runtime";import{useComposedRefs as p}from"@tamagui/compose-refs";import{createContext as x}from"@tamagui/create-context";import{focusFocusable as F}from"@tamagui/focusable";import{getButtonSized as E}from"@tamagui/get-button-sized";import{getFontSized as M}from"@tamagui/get-font-sized";import{SizableText as z}from"@tamagui/text";import{isWeb as d,styled as A,themeable as B,useId as S}from"@tamagui/web";import*as s from"react";const m="Label",[T,k]=x(m,{id:void 0,controlRef:{current:null}}),L=A(z,{name:"Label",tag:"label",variants:{unstyled:{false:{size:"$true",color:"$color",backgroundColor:"transparent",display:"flex",alignItems:"center",userSelect:"none",cursor:"default",pressStyle:{color:"$colorPress"}}},size:{"...size":(e,r)=>{const o=E(e,r);return{...M(e,r),height:o.height,lineHeight:o.height}}}},defaultVariants:{unstyled:!1}}),y=s.forwardRef((e,r)=>{const{htmlFor:o,id:R,...h}=e,l=s.useRef(null),f=s.useRef(null),C=p(r,f),P=S(),n=R??P;return d&&s.useEffect(()=>{if(o){const t=document.getElementById(o);if(f.current&&t){const i=()=>t.getAttribute("aria-labelledby"),c=[n,i()].filter(Boolean).join(" ");return t.setAttribute("aria-labelledby",c),l.current=t,()=>{var b;if(!n)return;const u=(b=i())==null?void 0:b.replace(n,"");u===""?t.removeAttribute("aria-labelledby"):u&&t.setAttribute("aria-labelledby",u)}}}},[n,o]),g(T,{id:n,controlRef:l,children:g(L,{role:"heading",id:n,htmlFor:o,...h,ref:C,onMouseDown:t=>{var a;(a=e.onMouseDown)==null||a.call(e,t),!t.defaultPrevented&&t.detail>1&&t.preventDefault()},onPress:t=>{var a;if((a=e.onPress)==null||a.call(e,t),d){if(o||!l.current||t.defaultPrevented)return;const i=l.current.contains(t.target),c=t.isTrusted===!0;!i&&c&&(l.current.click(),l.current.focus())}else e.htmlFor&&F(e.htmlFor)}})})});y.displayName=m;const w=L.extractable(B(y),{neverFlatten:!0}),U=e=>{const r=k("LabelConsumer"),{controlRef:o}=r;return s.useEffect(()=>{e&&(o.current=e)},[e,o]),r.id},q=w;export{w as Label,L as LabelFrame,U as useLabelContext};
|
|
144
2
|
//# sourceMappingURL=Label.js.map
|
package/dist/esm/Label.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Label.tsx"],
|
|
4
4
|
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n} from '@tamagui/web'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n color: '$color',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n },\n },\n\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\n },\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\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 if (!id) return\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\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n role=\"heading\"\n id={id}\n // @ts-ignore\n htmlFor={htmlFor}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (htmlFor || !controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\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 } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const 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"],
|
|
5
|
-
"mappings": "AA6GQ
|
|
6
|
-
"names": ["ariaLabelledBy"]
|
|
5
|
+
"mappings": "AA6GQ,cAAAA,MAAA,oBA7GR,OAAS,mBAAAC,MAAuB,wBAChC,OAAS,iBAAAC,MAAqB,0BAC9B,OAAS,kBAAAC,MAAsB,qBAC/B,OAAS,kBAAAC,MA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UAAU,IAAM,CAChBmB,IAASL,EAAW,QAAUK,EACpC,EAAG,CAACA,EAASL,CAAU,CAAC,EAEjBc,EAAQ,EACjB,EAEMC,EAAOH",
|
|
6
|
+
"names": ["jsx", "useComposedRefs", "createContext", "focusFocusable", "getButtonSized", "getFontSized", "SizableText", "isWeb", "styled", "themeable", "useId", "React", "NAME", "LabelProvider", "useLabelContextImpl", "LabelFrame", "val", "extras", "buttonStyle", "LabelComponent", "props", "forwardedRef", "htmlFor", "idProp", "labelProps", "controlRef", "ref", "composedRefs", "backupId", "id", "element", "getAriaLabel", "ariaLabelledBy", "_a", "event", "isClickingControl", "isUserClick", "Label", "useLabelContext", "context", "Root"]
|
|
7
7
|
}
|
package/dist/esm/Label.mjs
CHANGED
|
@@ -1,144 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
3
|
-
import { createContext } from "@tamagui/create-context";
|
|
4
|
-
import { focusFocusable } from "@tamagui/focusable";
|
|
5
|
-
import { getButtonSized } from "@tamagui/get-button-sized";
|
|
6
|
-
import { getFontSized } from "@tamagui/get-font-sized";
|
|
7
|
-
import { SizableText } from "@tamagui/text";
|
|
8
|
-
import {
|
|
9
|
-
isWeb,
|
|
10
|
-
styled,
|
|
11
|
-
themeable,
|
|
12
|
-
useId
|
|
13
|
-
} from "@tamagui/web";
|
|
14
|
-
import * as React from "react";
|
|
15
|
-
const NAME = "Label";
|
|
16
|
-
const [LabelProvider, useLabelContextImpl] = createContext(NAME, {
|
|
17
|
-
id: void 0,
|
|
18
|
-
controlRef: { current: null }
|
|
19
|
-
});
|
|
20
|
-
const LabelFrame = styled(SizableText, {
|
|
21
|
-
name: "Label",
|
|
22
|
-
tag: "label",
|
|
23
|
-
variants: {
|
|
24
|
-
unstyled: {
|
|
25
|
-
false: {
|
|
26
|
-
size: "$true",
|
|
27
|
-
color: "$color",
|
|
28
|
-
backgroundColor: "transparent",
|
|
29
|
-
display: "flex",
|
|
30
|
-
alignItems: "center",
|
|
31
|
-
userSelect: "none",
|
|
32
|
-
cursor: "default",
|
|
33
|
-
pressStyle: {
|
|
34
|
-
color: "$colorPress"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
size: {
|
|
39
|
-
"...size": (val, extras) => {
|
|
40
|
-
const buttonStyle = getButtonSized(val, extras);
|
|
41
|
-
return {
|
|
42
|
-
...getFontSized(val, extras),
|
|
43
|
-
height: buttonStyle.height,
|
|
44
|
-
lineHeight: buttonStyle.height
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
defaultVariants: {
|
|
50
|
-
unstyled: false
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const LabelComponent = React.forwardRef(
|
|
54
|
-
(props, forwardedRef) => {
|
|
55
|
-
const { htmlFor, id: idProp, ...labelProps } = props;
|
|
56
|
-
const controlRef = React.useRef(null);
|
|
57
|
-
const ref = React.useRef(null);
|
|
58
|
-
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
59
|
-
const backupId = useId();
|
|
60
|
-
const id = idProp ?? backupId;
|
|
61
|
-
if (isWeb) {
|
|
62
|
-
React.useEffect(() => {
|
|
63
|
-
if (htmlFor) {
|
|
64
|
-
const element = document.getElementById(htmlFor);
|
|
65
|
-
const label = ref.current;
|
|
66
|
-
if (label && element) {
|
|
67
|
-
const getAriaLabel = () => element.getAttribute("aria-labelledby");
|
|
68
|
-
const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(" ");
|
|
69
|
-
element.setAttribute("aria-labelledby", ariaLabelledBy);
|
|
70
|
-
controlRef.current = element;
|
|
71
|
-
return () => {
|
|
72
|
-
var _a;
|
|
73
|
-
if (!id)
|
|
74
|
-
return;
|
|
75
|
-
const ariaLabelledBy2 = (_a = getAriaLabel()) == null ? void 0 : _a.replace(id, "");
|
|
76
|
-
if (ariaLabelledBy2 === "") {
|
|
77
|
-
element.removeAttribute("aria-labelledby");
|
|
78
|
-
} else if (ariaLabelledBy2) {
|
|
79
|
-
element.setAttribute("aria-labelledby", ariaLabelledBy2);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}, [id, htmlFor]);
|
|
85
|
-
}
|
|
86
|
-
return /* @__PURE__ */ jsx(LabelProvider, { id, controlRef, children: /* @__PURE__ */ jsx(
|
|
87
|
-
LabelFrame,
|
|
88
|
-
{
|
|
89
|
-
role: "heading",
|
|
90
|
-
id,
|
|
91
|
-
htmlFor,
|
|
92
|
-
...labelProps,
|
|
93
|
-
ref: composedRefs,
|
|
94
|
-
onMouseDown: (event) => {
|
|
95
|
-
var _a;
|
|
96
|
-
(_a = props.onMouseDown) == null ? void 0 : _a.call(props, event);
|
|
97
|
-
if (!event.defaultPrevented && event.detail > 1) {
|
|
98
|
-
event.preventDefault();
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
onPress: (event) => {
|
|
102
|
-
var _a;
|
|
103
|
-
(_a = props.onPress) == null ? void 0 : _a.call(props, event);
|
|
104
|
-
if (isWeb) {
|
|
105
|
-
if (htmlFor || !controlRef.current || event.defaultPrevented)
|
|
106
|
-
return;
|
|
107
|
-
const isClickingControl = controlRef.current.contains(
|
|
108
|
-
event.target
|
|
109
|
-
);
|
|
110
|
-
const isUserClick = event.isTrusted === true;
|
|
111
|
-
if (!isClickingControl && isUserClick) {
|
|
112
|
-
controlRef.current.click();
|
|
113
|
-
controlRef.current.focus();
|
|
114
|
-
}
|
|
115
|
-
} else {
|
|
116
|
-
if (props.htmlFor) {
|
|
117
|
-
focusFocusable(props.htmlFor);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
) });
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
LabelComponent.displayName = NAME;
|
|
126
|
-
const Label = LabelFrame.extractable(themeable(LabelComponent), {
|
|
127
|
-
neverFlatten: true
|
|
128
|
-
});
|
|
129
|
-
const useLabelContext = (element) => {
|
|
130
|
-
const context = useLabelContextImpl("LabelConsumer");
|
|
131
|
-
const { controlRef } = context;
|
|
132
|
-
React.useEffect(() => {
|
|
133
|
-
if (element)
|
|
134
|
-
controlRef.current = element;
|
|
135
|
-
}, [element, controlRef]);
|
|
136
|
-
return context.id;
|
|
137
|
-
};
|
|
138
|
-
const Root = Label;
|
|
139
|
-
export {
|
|
140
|
-
Label,
|
|
141
|
-
LabelFrame,
|
|
142
|
-
useLabelContext
|
|
143
|
-
};
|
|
1
|
+
import{jsx as g}from"react/jsx-runtime";import{useComposedRefs as p}from"@tamagui/compose-refs";import{createContext as x}from"@tamagui/create-context";import{focusFocusable as F}from"@tamagui/focusable";import{getButtonSized as E}from"@tamagui/get-button-sized";import{getFontSized as M}from"@tamagui/get-font-sized";import{SizableText as z}from"@tamagui/text";import{isWeb as d,styled as A,themeable as B,useId as S}from"@tamagui/web";import*as s from"react";const m="Label",[T,k]=x(m,{id:void 0,controlRef:{current:null}}),L=A(z,{name:"Label",tag:"label",variants:{unstyled:{false:{size:"$true",color:"$color",backgroundColor:"transparent",display:"flex",alignItems:"center",userSelect:"none",cursor:"default",pressStyle:{color:"$colorPress"}}},size:{"...size":(e,r)=>{const o=E(e,r);return{...M(e,r),height:o.height,lineHeight:o.height}}}},defaultVariants:{unstyled:!1}}),y=s.forwardRef((e,r)=>{const{htmlFor:o,id:R,...h}=e,l=s.useRef(null),f=s.useRef(null),C=p(r,f),P=S(),n=R??P;return d&&s.useEffect(()=>{if(o){const t=document.getElementById(o);if(f.current&&t){const i=()=>t.getAttribute("aria-labelledby"),c=[n,i()].filter(Boolean).join(" ");return t.setAttribute("aria-labelledby",c),l.current=t,()=>{var b;if(!n)return;const u=(b=i())==null?void 0:b.replace(n,"");u===""?t.removeAttribute("aria-labelledby"):u&&t.setAttribute("aria-labelledby",u)}}}},[n,o]),g(T,{id:n,controlRef:l,children:g(L,{role:"heading",id:n,htmlFor:o,...h,ref:C,onMouseDown:t=>{var a;(a=e.onMouseDown)==null||a.call(e,t),!t.defaultPrevented&&t.detail>1&&t.preventDefault()},onPress:t=>{var a;if((a=e.onPress)==null||a.call(e,t),d){if(o||!l.current||t.defaultPrevented)return;const i=l.current.contains(t.target),c=t.isTrusted===!0;!i&&c&&(l.current.click(),l.current.focus())}else e.htmlFor&&F(e.htmlFor)}})})});y.displayName=m;const w=L.extractable(B(y),{neverFlatten:!0}),U=e=>{const r=k("LabelConsumer"),{controlRef:o}=r;return s.useEffect(()=>{e&&(o.current=e)},[e,o]),r.id},q=w;export{w as Label,L as LabelFrame,U as useLabelContext};
|
|
144
2
|
//# sourceMappingURL=Label.mjs.map
|
package/dist/esm/Label.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Label.tsx"],
|
|
4
4
|
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n} from '@tamagui/web'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n color: '$color',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n },\n },\n\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\n },\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\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 if (!id) return\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\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n role=\"heading\"\n id={id}\n // @ts-ignore\n htmlFor={htmlFor}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (htmlFor || !controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\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 } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const 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"],
|
|
5
|
-
"mappings": "AA6GQ
|
|
6
|
-
"names": ["ariaLabelledBy"]
|
|
5
|
+
"mappings": "AA6GQ,cAAAA,MAAA,oBA7GR,OAAS,mBAAAC,MAAuB,wBAChC,OAAS,iBAAAC,MAAqB,0BAC9B,OAAS,kBAAAC,MAAsB,qBAC/B,OAAS,kBAAAC,MAAsB,4BAC/B,OAAS,gBAAAC,MAAoB,0BAC7B,OAAS,eAAAC,MAAmB,gBAC5B,OAGE,SAAAC,EACA,UAAAC,EACA,aAAAC,EACA,SAAAC,MACK,eACP,UAAYC,MAAW,QAGvB,MAAMC,EAAO,QAOP,CAACC,EAAeC,CAAmB,EAAIZ,EAAiCU,EAAM,CAClF,GAAI,OACJ,WAAY,CAAE,QAAS,IAAK,CAC9B,CAAC,EAEYG,EAAaP,EAAOF,EAAa,CAC5C,KAAM,QACN,IAAK,QAEL,SAAU,CACR,SAAU,CACR,MAAO,CACL,KAAM,QACN,MAAO,SACP,gBAAiB,cACjB,QAAS,OACT,WAAY,SACZ,WAAY,OACZ,OAAQ,UACR,WAAY,CACV,MAAO,aACT,CACF,CACF,EAEA,KAAM,CACJ,UA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,GAqHYA,EAAAb,EAAM,cAAN,MAAAa,EAAA,KAAAb,EAAoBc,GAEhB,CAACA,EAAM,kBAAoBA,EAAM,OAAS,GAC5CA,EAAM,eAAe,CAEzB,EACA,QAAUA,GAAU,CA3H9B,IAAAD,EA8HY,IAFAA,EAAAb,EAAM,UAAN,MAAAa,EAAA,KAAAb,EAAgBc,GAEZ3B,EAAO,CACT,GAAIe,GAAW,CAACG,EAAW,SAAWS,EAAM,iBAAkB,OAC9D,MAAMC,EAAoBV,EAAW,QAAQ,SAC3CS,EAAM,MACR,EAGME,EAAcF,EAAM,YAAc,GAMpC,CAACC,GAAqBC,IACxBX,EAAW,QAAQ,MAAM,EACzBA,EAAW,QAAQ,MAAM,EAE7B,MACML,EAAM,SACRjB,EAAeiB,EAAM,OAAO,CAGlC,EACF,EACF,CAEJ,CACF,EAEAD,EAAe,YAAcP,EAEtB,MAAMyB,EACXtB,EAAW,YAAYN,EAAUU,CAAqB,EAAU,CAC9D,aAAc,EAChB,CAAC,EAEUmB,EAAmBR,GAAiC,CAC/D,MAAMS,EAAUzB,EAAoB,eAAe,EAC7C,CAAE,WAAAW,CAAW,EAAIc,EAEvB,OAAA5B,EAAM,UAAU,IAAM,CAChBmB,IAASL,EAAW,QAAUK,EACpC,EAAG,CAACA,EAASL,CAAU,CAAC,EAEjBc,EAAQ,EACjB,EAEMC,EAAOH",
|
|
6
|
+
"names": ["jsx", "useComposedRefs", "createContext", "focusFocusable", "getButtonSized", "getFontSized", "SizableText", "isWeb", "styled", "themeable", "useId", "React", "NAME", "LabelProvider", "useLabelContextImpl", "LabelFrame", "val", "extras", "buttonStyle", "LabelComponent", "props", "forwardedRef", "htmlFor", "idProp", "labelProps", "controlRef", "ref", "composedRefs", "backupId", "id", "element", "getAriaLabel", "ariaLabelledBy", "_a", "event", "isClickingControl", "isUserClick", "Label", "useLabelContext", "context", "Root"]
|
|
7
7
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export*from"./Label";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export*from"./Label";
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
package/dist/jsx/Label.js
CHANGED
|
@@ -1,137 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createContext } from "@tamagui/create-context";
|
|
3
|
-
import { focusFocusable } from "@tamagui/focusable";
|
|
4
|
-
import { getButtonSized } from "@tamagui/get-button-sized";
|
|
5
|
-
import { getFontSized } from "@tamagui/get-font-sized";
|
|
6
|
-
import { SizableText } from "@tamagui/text";
|
|
7
|
-
import {
|
|
8
|
-
isWeb,
|
|
9
|
-
styled,
|
|
10
|
-
themeable,
|
|
11
|
-
useId
|
|
12
|
-
} from "@tamagui/web";
|
|
13
|
-
import * as React from "react";
|
|
14
|
-
const NAME = "Label";
|
|
15
|
-
const [LabelProvider, useLabelContextImpl] = createContext(NAME, {
|
|
16
|
-
id: void 0,
|
|
17
|
-
controlRef: { current: null }
|
|
18
|
-
});
|
|
19
|
-
const LabelFrame = styled(SizableText, {
|
|
20
|
-
name: "Label",
|
|
21
|
-
tag: "label",
|
|
22
|
-
variants: {
|
|
23
|
-
unstyled: {
|
|
24
|
-
false: {
|
|
25
|
-
size: "$true",
|
|
26
|
-
color: "$color",
|
|
27
|
-
backgroundColor: "transparent",
|
|
28
|
-
display: "flex",
|
|
29
|
-
alignItems: "center",
|
|
30
|
-
userSelect: "none",
|
|
31
|
-
cursor: "default",
|
|
32
|
-
pressStyle: {
|
|
33
|
-
color: "$colorPress"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
size: {
|
|
38
|
-
"...size": (val, extras) => {
|
|
39
|
-
const buttonStyle = getButtonSized(val, extras);
|
|
40
|
-
return {
|
|
41
|
-
...getFontSized(val, extras),
|
|
42
|
-
height: buttonStyle.height,
|
|
43
|
-
lineHeight: buttonStyle.height
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
defaultVariants: {
|
|
49
|
-
unstyled: false
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
const LabelComponent = React.forwardRef(
|
|
53
|
-
(props, forwardedRef) => {
|
|
54
|
-
const { htmlFor, id: idProp, ...labelProps } = props;
|
|
55
|
-
const controlRef = React.useRef(null);
|
|
56
|
-
const ref = React.useRef(null);
|
|
57
|
-
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
58
|
-
const backupId = useId();
|
|
59
|
-
const id = idProp ?? backupId;
|
|
60
|
-
if (isWeb) {
|
|
61
|
-
React.useEffect(() => {
|
|
62
|
-
if (htmlFor) {
|
|
63
|
-
const element = document.getElementById(htmlFor);
|
|
64
|
-
const label = ref.current;
|
|
65
|
-
if (label && element) {
|
|
66
|
-
const getAriaLabel = () => element.getAttribute("aria-labelledby");
|
|
67
|
-
const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(" ");
|
|
68
|
-
element.setAttribute("aria-labelledby", ariaLabelledBy);
|
|
69
|
-
controlRef.current = element;
|
|
70
|
-
return () => {
|
|
71
|
-
if (!id)
|
|
72
|
-
return;
|
|
73
|
-
const ariaLabelledBy2 = getAriaLabel()?.replace(id, "");
|
|
74
|
-
if (ariaLabelledBy2 === "") {
|
|
75
|
-
element.removeAttribute("aria-labelledby");
|
|
76
|
-
} else if (ariaLabelledBy2) {
|
|
77
|
-
element.setAttribute("aria-labelledby", ariaLabelledBy2);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}, [id, htmlFor]);
|
|
83
|
-
}
|
|
84
|
-
return <LabelProvider id={id} controlRef={controlRef}><LabelFrame
|
|
85
|
-
role="heading"
|
|
86
|
-
id={id}
|
|
87
|
-
htmlFor={htmlFor}
|
|
88
|
-
{...labelProps}
|
|
89
|
-
ref={composedRefs}
|
|
90
|
-
onMouseDown={(event) => {
|
|
91
|
-
props.onMouseDown?.(event);
|
|
92
|
-
if (!event.defaultPrevented && event.detail > 1) {
|
|
93
|
-
event.preventDefault();
|
|
94
|
-
}
|
|
95
|
-
}}
|
|
96
|
-
onPress={(event) => {
|
|
97
|
-
props.onPress?.(event);
|
|
98
|
-
if (isWeb) {
|
|
99
|
-
if (htmlFor || !controlRef.current || event.defaultPrevented)
|
|
100
|
-
return;
|
|
101
|
-
const isClickingControl = controlRef.current.contains(
|
|
102
|
-
event.target
|
|
103
|
-
);
|
|
104
|
-
const isUserClick = event.isTrusted === true;
|
|
105
|
-
if (!isClickingControl && isUserClick) {
|
|
106
|
-
controlRef.current.click();
|
|
107
|
-
controlRef.current.focus();
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
if (props.htmlFor) {
|
|
111
|
-
focusFocusable(props.htmlFor);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}}
|
|
115
|
-
/></LabelProvider>;
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
LabelComponent.displayName = NAME;
|
|
119
|
-
const Label = LabelFrame.extractable(themeable(LabelComponent), {
|
|
120
|
-
neverFlatten: true
|
|
121
|
-
});
|
|
122
|
-
const useLabelContext = (element) => {
|
|
123
|
-
const context = useLabelContextImpl("LabelConsumer");
|
|
124
|
-
const { controlRef } = context;
|
|
125
|
-
React.useEffect(() => {
|
|
126
|
-
if (element)
|
|
127
|
-
controlRef.current = element;
|
|
128
|
-
}, [element, controlRef]);
|
|
129
|
-
return context.id;
|
|
130
|
-
};
|
|
131
|
-
const Root = Label;
|
|
132
|
-
export {
|
|
133
|
-
Label,
|
|
134
|
-
LabelFrame,
|
|
135
|
-
useLabelContext
|
|
136
|
-
};
|
|
1
|
+
import{useComposedRefs as x}from"@tamagui/compose-refs";import{createContext as F}from"@tamagui/create-context";import{focusFocusable as E}from"@tamagui/focusable";import{getButtonSized as M}from"@tamagui/get-button-sized";import{getFontSized as z}from"@tamagui/get-font-sized";import{SizableText as A}from"@tamagui/text";import{isWeb as f,styled as B,themeable as S,useId as T}from"@tamagui/web";import*as a from"react";const b="Label",[H,I]=F(b,{id:void 0,controlRef:{current:null}}),L=B(A,{name:"Label",tag:"label",variants:{unstyled:{false:{size:"$true",color:"$color",backgroundColor:"transparent",display:"flex",alignItems:"center",userSelect:"none",cursor:"default",pressStyle:{color:"$colorPress"}}},size:{"...size":(t,r)=>{const o=M(t,r);return{...z(t,r),height:o.height,lineHeight:o.height}}}},defaultVariants:{unstyled:!1}}),y=a.forwardRef((t,r)=>{const{htmlFor:o,id:g,...R}=t,l=a.useRef(null),c=a.useRef(null),h=x(r,c),C=T(),n=g??C;return f&&a.useEffect(()=>{if(o){const e=document.getElementById(o);if(c.current&&e){const s=()=>e.getAttribute("aria-labelledby"),P=[n,s()].filter(Boolean).join(" ");return e.setAttribute("aria-labelledby",P),l.current=e,()=>{if(!n)return;const i=s()?.replace(n,"");i===""?e.removeAttribute("aria-labelledby"):i&&e.setAttribute("aria-labelledby",i)}}}},[n,o]),<H id={n}controlRef={l}><L role="heading"id={n}htmlFor={o}{...R}ref={h}onMouseDown={e=>{t.onMouseDown?.(e),!e.defaultPrevented&&e.detail>1&&e.preventDefault()}}onPress={e=>{if(t.onPress?.(e),f){if(o||!l.current||e.defaultPrevented)return;const u=l.current.contains(e.target),s=e.isTrusted===!0;!u&&s&&(l.current.click(),l.current.focus())}else t.htmlFor&&E(t.htmlFor)}}/></H>});y.displayName=b;const V=L.extractable(S(y),{neverFlatten:!0}),K=t=>{const r=I("LabelConsumer"),{controlRef:o}=r;return a.useEffect(()=>{t&&(o.current=t)},[t,o]),r.id},Q=V;export{V as Label,L as LabelFrame,K as useLabelContext};
|
|
137
2
|
//# sourceMappingURL=Label.js.map
|
package/dist/jsx/Label.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Label.tsx"],
|
|
4
4
|
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n} from '@tamagui/web'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n color: '$color',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n },\n },\n\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\n },\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\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 if (!id) return\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\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n role=\"heading\"\n id={id}\n // @ts-ignore\n htmlFor={htmlFor}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (htmlFor || !controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\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 } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const 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])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EAAUxB,EAAoB,eAAe,EAC7C,CAAE,WAAAW,CAAW,EAAIa,EAEvB,OAAA3B,EAAM,UAAU,IAAM,CAChBmB,IAASL,EAAW,QAAUK,EACpC,EAAG,CAACA,EAASL,CAAU,CAAC,EAEjBa,EAAQ,EACjB,EAEMC,EAAOH",
|
|
6
|
+
"names": ["useComposedRefs", "createContext", "focusFocusable", "getButtonSized", "getFontSized", "SizableText", "isWeb", "styled", "themeable", "useId", "React", "NAME", "LabelProvider", "useLabelContextImpl", "LabelFrame", "val", "extras", "buttonStyle", "LabelComponent", "props", "forwardedRef", "htmlFor", "idProp", "labelProps", "controlRef", "ref", "composedRefs", "backupId", "id", "element", "getAriaLabel", "ariaLabelledBy", "event", "isClickingControl", "isUserClick", "Label", "useLabelContext", "context", "Root"]
|
|
7
7
|
}
|
package/dist/jsx/Label.mjs
CHANGED
|
@@ -1,137 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createContext } from "@tamagui/create-context";
|
|
3
|
-
import { focusFocusable } from "@tamagui/focusable";
|
|
4
|
-
import { getButtonSized } from "@tamagui/get-button-sized";
|
|
5
|
-
import { getFontSized } from "@tamagui/get-font-sized";
|
|
6
|
-
import { SizableText } from "@tamagui/text";
|
|
7
|
-
import {
|
|
8
|
-
isWeb,
|
|
9
|
-
styled,
|
|
10
|
-
themeable,
|
|
11
|
-
useId
|
|
12
|
-
} from "@tamagui/web";
|
|
13
|
-
import * as React from "react";
|
|
14
|
-
const NAME = "Label";
|
|
15
|
-
const [LabelProvider, useLabelContextImpl] = createContext(NAME, {
|
|
16
|
-
id: void 0,
|
|
17
|
-
controlRef: { current: null }
|
|
18
|
-
});
|
|
19
|
-
const LabelFrame = styled(SizableText, {
|
|
20
|
-
name: "Label",
|
|
21
|
-
tag: "label",
|
|
22
|
-
variants: {
|
|
23
|
-
unstyled: {
|
|
24
|
-
false: {
|
|
25
|
-
size: "$true",
|
|
26
|
-
color: "$color",
|
|
27
|
-
backgroundColor: "transparent",
|
|
28
|
-
display: "flex",
|
|
29
|
-
alignItems: "center",
|
|
30
|
-
userSelect: "none",
|
|
31
|
-
cursor: "default",
|
|
32
|
-
pressStyle: {
|
|
33
|
-
color: "$colorPress"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
size: {
|
|
38
|
-
"...size": (val, extras) => {
|
|
39
|
-
const buttonStyle = getButtonSized(val, extras);
|
|
40
|
-
return {
|
|
41
|
-
...getFontSized(val, extras),
|
|
42
|
-
height: buttonStyle.height,
|
|
43
|
-
lineHeight: buttonStyle.height
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
defaultVariants: {
|
|
49
|
-
unstyled: false
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
const LabelComponent = React.forwardRef(
|
|
53
|
-
(props, forwardedRef) => {
|
|
54
|
-
const { htmlFor, id: idProp, ...labelProps } = props;
|
|
55
|
-
const controlRef = React.useRef(null);
|
|
56
|
-
const ref = React.useRef(null);
|
|
57
|
-
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
58
|
-
const backupId = useId();
|
|
59
|
-
const id = idProp ?? backupId;
|
|
60
|
-
if (isWeb) {
|
|
61
|
-
React.useEffect(() => {
|
|
62
|
-
if (htmlFor) {
|
|
63
|
-
const element = document.getElementById(htmlFor);
|
|
64
|
-
const label = ref.current;
|
|
65
|
-
if (label && element) {
|
|
66
|
-
const getAriaLabel = () => element.getAttribute("aria-labelledby");
|
|
67
|
-
const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(" ");
|
|
68
|
-
element.setAttribute("aria-labelledby", ariaLabelledBy);
|
|
69
|
-
controlRef.current = element;
|
|
70
|
-
return () => {
|
|
71
|
-
if (!id)
|
|
72
|
-
return;
|
|
73
|
-
const ariaLabelledBy2 = getAriaLabel()?.replace(id, "");
|
|
74
|
-
if (ariaLabelledBy2 === "") {
|
|
75
|
-
element.removeAttribute("aria-labelledby");
|
|
76
|
-
} else if (ariaLabelledBy2) {
|
|
77
|
-
element.setAttribute("aria-labelledby", ariaLabelledBy2);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}, [id, htmlFor]);
|
|
83
|
-
}
|
|
84
|
-
return <LabelProvider id={id} controlRef={controlRef}><LabelFrame
|
|
85
|
-
role="heading"
|
|
86
|
-
id={id}
|
|
87
|
-
htmlFor={htmlFor}
|
|
88
|
-
{...labelProps}
|
|
89
|
-
ref={composedRefs}
|
|
90
|
-
onMouseDown={(event) => {
|
|
91
|
-
props.onMouseDown?.(event);
|
|
92
|
-
if (!event.defaultPrevented && event.detail > 1) {
|
|
93
|
-
event.preventDefault();
|
|
94
|
-
}
|
|
95
|
-
}}
|
|
96
|
-
onPress={(event) => {
|
|
97
|
-
props.onPress?.(event);
|
|
98
|
-
if (isWeb) {
|
|
99
|
-
if (htmlFor || !controlRef.current || event.defaultPrevented)
|
|
100
|
-
return;
|
|
101
|
-
const isClickingControl = controlRef.current.contains(
|
|
102
|
-
event.target
|
|
103
|
-
);
|
|
104
|
-
const isUserClick = event.isTrusted === true;
|
|
105
|
-
if (!isClickingControl && isUserClick) {
|
|
106
|
-
controlRef.current.click();
|
|
107
|
-
controlRef.current.focus();
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
if (props.htmlFor) {
|
|
111
|
-
focusFocusable(props.htmlFor);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}}
|
|
115
|
-
/></LabelProvider>;
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
LabelComponent.displayName = NAME;
|
|
119
|
-
const Label = LabelFrame.extractable(themeable(LabelComponent), {
|
|
120
|
-
neverFlatten: true
|
|
121
|
-
});
|
|
122
|
-
const useLabelContext = (element) => {
|
|
123
|
-
const context = useLabelContextImpl("LabelConsumer");
|
|
124
|
-
const { controlRef } = context;
|
|
125
|
-
React.useEffect(() => {
|
|
126
|
-
if (element)
|
|
127
|
-
controlRef.current = element;
|
|
128
|
-
}, [element, controlRef]);
|
|
129
|
-
return context.id;
|
|
130
|
-
};
|
|
131
|
-
const Root = Label;
|
|
132
|
-
export {
|
|
133
|
-
Label,
|
|
134
|
-
LabelFrame,
|
|
135
|
-
useLabelContext
|
|
136
|
-
};
|
|
1
|
+
import{useComposedRefs as x}from"@tamagui/compose-refs";import{createContext as F}from"@tamagui/create-context";import{focusFocusable as E}from"@tamagui/focusable";import{getButtonSized as M}from"@tamagui/get-button-sized";import{getFontSized as z}from"@tamagui/get-font-sized";import{SizableText as A}from"@tamagui/text";import{isWeb as f,styled as B,themeable as S,useId as T}from"@tamagui/web";import*as a from"react";const b="Label",[H,I]=F(b,{id:void 0,controlRef:{current:null}}),L=B(A,{name:"Label",tag:"label",variants:{unstyled:{false:{size:"$true",color:"$color",backgroundColor:"transparent",display:"flex",alignItems:"center",userSelect:"none",cursor:"default",pressStyle:{color:"$colorPress"}}},size:{"...size":(t,r)=>{const o=M(t,r);return{...z(t,r),height:o.height,lineHeight:o.height}}}},defaultVariants:{unstyled:!1}}),y=a.forwardRef((t,r)=>{const{htmlFor:o,id:g,...R}=t,l=a.useRef(null),c=a.useRef(null),h=x(r,c),C=T(),n=g??C;return f&&a.useEffect(()=>{if(o){const e=document.getElementById(o);if(c.current&&e){const s=()=>e.getAttribute("aria-labelledby"),P=[n,s()].filter(Boolean).join(" ");return e.setAttribute("aria-labelledby",P),l.current=e,()=>{if(!n)return;const i=s()?.replace(n,"");i===""?e.removeAttribute("aria-labelledby"):i&&e.setAttribute("aria-labelledby",i)}}}},[n,o]),<H id={n}controlRef={l}><L role="heading"id={n}htmlFor={o}{...R}ref={h}onMouseDown={e=>{t.onMouseDown?.(e),!e.defaultPrevented&&e.detail>1&&e.preventDefault()}}onPress={e=>{if(t.onPress?.(e),f){if(o||!l.current||e.defaultPrevented)return;const u=l.current.contains(e.target),s=e.isTrusted===!0;!u&&s&&(l.current.click(),l.current.focus())}else t.htmlFor&&E(t.htmlFor)}}/></H>});y.displayName=b;const V=L.extractable(S(y),{neverFlatten:!0}),K=t=>{const r=I("LabelConsumer"),{controlRef:o}=r;return a.useEffect(()=>{t&&(o.current=t)},[t,o]),r.id},Q=V;export{V as Label,L as LabelFrame,K as useLabelContext};
|
|
137
2
|
//# sourceMappingURL=Label.mjs.map
|
package/dist/jsx/Label.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Label.tsx"],
|
|
4
4
|
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { getButtonSized } from '@tamagui/get-button-sized'\nimport { getFontSized } from '@tamagui/get-font-sized'\nimport { SizableText } from '@tamagui/text'\nimport {\n GetProps,\n ReactComponentWithRef,\n isWeb,\n styled,\n themeable,\n useId,\n} from '@tamagui/web'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst NAME = 'Label'\n\ntype LabelContextValue = {\n id?: string\n controlRef: React.MutableRefObject<HTMLElement | null>\n}\n\nconst [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {\n id: undefined,\n controlRef: { current: null },\n})\n\nexport const LabelFrame = styled(SizableText, {\n name: 'Label',\n tag: 'label',\n\n variants: {\n unstyled: {\n false: {\n size: '$true',\n color: '$color',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n userSelect: 'none',\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n },\n },\n\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSized(val, extras)\n return {\n ...getFontSized(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n } as const,\n\n defaultVariants: {\n unstyled: false,\n },\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>(\n (props, forwardedRef) => {\n const { htmlFor, id: idProp, ...labelProps } = props\n const controlRef = React.useRef<HTMLElement | null>(null)\n const ref = React.useRef<any>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const backupId = useId()\n const id = idProp ?? backupId\n\n if (isWeb) {\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 if (!id) return\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\n return (\n <LabelProvider id={id} controlRef={controlRef}>\n <LabelFrame\n role=\"heading\"\n id={id}\n // @ts-ignore\n htmlFor={htmlFor}\n {...labelProps}\n ref={composedRefs as any}\n onMouseDown={(event) => {\n props.onMouseDown?.(event)\n // prevent text selection when double clicking label\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (htmlFor || !controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(\n event.target as any as Node\n )\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 } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\n )\n }\n)\n\nLabelComponent.displayName = NAME\n\nexport const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =\n LabelFrame.extractable(themeable(LabelComponent as any) as any, {\n neverFlatten: true,\n })\n\nexport const 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"],
|
|
5
|
-
"mappings": "AAAA,
|
|
6
|
-
"names": ["ariaLabelledBy"]
|
|
5
|
+
"mappings": "AAAA,OAAS,mBAAAA,MAAuB,wBAChC,OAAS,iBAAAC,MAAqB,0BAC9B,OAAS,kBAAAC,MAAsB,qBAC/B,OAAS,kBAAAC,MAAsB,4BAC/B,OAAS,gBAAAC,MAAoB,0BAC7B,OAAS,eAAAC,MAAmB,gBAC5B,OAGE,SAAAC,EACA,UAAAC,EACA,aAAAC,EACA,SAAAC,MACK,eACP,UAAYC,MAAW,QAGvB,MAAMC,EAAO,QAOP,CAACC,EAAeC,CAAmB,EAAIZ,EAAiCU,EAAM,CAClF,GAAI,OACJ,WAAY,CAAE,QAAS,IAAK,CAC9B,CAAC,EAEYG,EAAaP,EAAOF,EAAa,CAC5C,KAAM,QACN,IAAK,QAEL,SAAU,CACR,SAAU,CACR,MAAO,CACL,KAAM,QACN,MAAO,SACP,gBAAiB,cACjB,QAAS,OACT,WAAY,SACZ,WAAY,OACZ,OAAQ,UACR,WAAY,CACV,MAAO,aACT,CACF,CACF,EAEA,KAAM,CACJ,UAAW,CAACU,EAAKC,IAAW,CAC1B,MAAMC,EAAcd,EAAeY,EAAKC,CAAM,EAC9C,MAAO,CACL,GAAGZ,EAAaW,EAAKC,CAAM,EAC3B,OAAQC,EAAY,OACpB,WAAYA,EAAY,MAC1B,CACF,CACF,CACF,EAEA,gBAAiB,CACf,SAAU,EACZ,CACF,CAAC,EAMKC,EAAiBR,EAAM,W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ACxBV,EAAW,QAAQ,MAAM,EACzBA,EAAW,QAAQ,MAAM,EAE7B,MACML,EAAM,SACRjB,EAAeiB,EAAM,OAAO,CAGlC,EACF,EACF,EA1CCP,EA4CL,CACF,EAEAM,EAAe,YAAcP,EAEtB,MAAMwB,EACXrB,EAAW,YAAYN,EAAUU,CAAqB,EAAU,CAC9D,aAAc,EAChB,CAAC,EAEUkB,EAAmBP,GAAiC,CAC/D,MAAMQ,EAAUxB,EAAoB,eAAe,EAC7C,CAAE,WAAAW,CAAW,EAAIa,EAEvB,OAAA3B,EAAM,UAAU,IAAM,CAChBmB,IAASL,EAAW,QAAUK,EACpC,EAAG,CAACA,EAASL,CAAU,CAAC,EAEjBa,EAAQ,EACjB,EAEMC,EAAOH",
|
|
6
|
+
"names": ["useComposedRefs", "createContext", "focusFocusable", "getButtonSized", "getFontSized", "SizableText", "isWeb", "styled", "themeable", "useId", "React", "NAME", "LabelProvider", "useLabelContextImpl", "LabelFrame", "val", "extras", "buttonStyle", "LabelComponent", "props", "forwardedRef", "htmlFor", "idProp", "labelProps", "controlRef", "ref", "composedRefs", "backupId", "id", "element", "getAriaLabel", "ariaLabelledBy", "event", "isClickingControl", "isUserClick", "Label", "useLabelContext", "context", "Root"]
|
|
7
7
|
}
|
package/dist/jsx/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export*from"./Label";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/jsx/index.js.map
CHANGED
package/dist/jsx/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export*from"./Label";
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/jsx/index.mjs.map
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/label",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.4",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -31,20 +31,20 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@tamagui/compose-refs": "1.13.
|
|
35
|
-
"@tamagui/create-context": "1.13.
|
|
36
|
-
"@tamagui/focusable": "1.13.
|
|
37
|
-
"@tamagui/get-button-sized": "1.13.
|
|
38
|
-
"@tamagui/get-font-sized": "1.13.
|
|
39
|
-
"@tamagui/text": "1.13.
|
|
40
|
-
"@tamagui/web": "1.13.
|
|
34
|
+
"@tamagui/compose-refs": "1.13.4",
|
|
35
|
+
"@tamagui/create-context": "1.13.4",
|
|
36
|
+
"@tamagui/focusable": "1.13.4",
|
|
37
|
+
"@tamagui/get-button-sized": "1.13.4",
|
|
38
|
+
"@tamagui/get-font-sized": "1.13.4",
|
|
39
|
+
"@tamagui/text": "1.13.4",
|
|
40
|
+
"@tamagui/web": "1.13.4"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": "*",
|
|
44
44
|
"react-native": "*"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@tamagui/build": "1.13.
|
|
47
|
+
"@tamagui/build": "1.13.4",
|
|
48
48
|
"react": "^18.2.0",
|
|
49
49
|
"react-native": "^0.71.4"
|
|
50
50
|
},
|