@tamagui/label 2.7.7 → 3.0.0-beta.643.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/cjs/Label.cjs +112 -138
- package/dist/cjs/Label.native.cjs +149 -0
- package/dist/cjs/Label.native.js +117 -143
- package/dist/cjs/Label.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +21 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Label.mjs +95 -113
- package/dist/esm/Label.mjs.map +1 -1
- package/dist/esm/Label.native.js +101 -120
- package/dist/esm/Label.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/dist/jsx/Label.mjs +95 -113
- package/dist/jsx/Label.mjs.map +1 -1
- package/dist/jsx/Label.native.cjs +149 -0
- package/dist/jsx/Label.native.js +117 -143
- package/dist/jsx/Label.native.js.map +1 -1
- package/dist/jsx/index.js +1 -2
- package/dist/jsx/index.mjs +1 -2
- package/dist/jsx/index.native.cjs +21 -0
- package/dist/jsx/index.native.js +10 -10
- package/dist/jsx/index.native.js.map +1 -1
- package/package.json +11 -11
- package/src/Label.tsx +33 -33
- package/types/Label.d.ts +15 -11
- package/types/Label.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
package/dist/cjs/Label.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -5,164 +6,137 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
5
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
8
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
12
13
|
};
|
|
13
14
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
21
22
|
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
30
26
|
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
28
|
var Label_exports = {};
|
|
35
29
|
__export(Label_exports, {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
Label: () => Label,
|
|
31
|
+
LabelFrame: () => LabelFrame,
|
|
32
|
+
useLabelContext: () => useLabelContext
|
|
39
33
|
});
|
|
40
34
|
module.exports = __toCommonJS(Label_exports);
|
|
41
35
|
var import_compose_refs = require("@tamagui/compose-refs");
|
|
42
36
|
var import_constants = require("@tamagui/constants");
|
|
43
37
|
var import_create_context = require("@tamagui/create-context");
|
|
44
38
|
var import_focusable = require("@tamagui/focusable");
|
|
45
|
-
var import_get_button_sized = require("@tamagui/get-button-sized");
|
|
46
39
|
var import_get_font_sized = require("@tamagui/get-font-sized");
|
|
40
|
+
var import_size = require("@tamagui/size");
|
|
47
41
|
var import_text = require("@tamagui/text");
|
|
48
42
|
var import_web = require("@tamagui/web");
|
|
49
43
|
var React = __toESM(require("react"), 1);
|
|
50
44
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
51
45
|
const NAME = "Label";
|
|
52
46
|
const [LabelProvider, useLabelContextImpl] = (0, import_create_context.createContext)(NAME, {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
current: null
|
|
56
|
-
}
|
|
47
|
+
id: void 0,
|
|
48
|
+
controlRef: { current: null }
|
|
57
49
|
});
|
|
50
|
+
const labelSizeVariant = (val, extras) => {
|
|
51
|
+
const fontStyle = (0, import_get_font_sized.getFontSized)(val, extras);
|
|
52
|
+
const sizeKey = (0, import_size.resolveSizeToken)(val, "size");
|
|
53
|
+
return {
|
|
54
|
+
...fontStyle,
|
|
55
|
+
lineHeight: typeof sizeKey === "number" ? sizeKey : extras.tokens.size[sizeKey]
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
58
|
const LabelFrame = (0, import_web.styled)(import_text.SizableText, {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
pressStyle: {
|
|
72
|
-
color: "$colorPress"
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
size: {
|
|
77
|
-
"...size": (val, extras) => {
|
|
78
|
-
const buttonStyle = (0, import_get_button_sized.getButtonSized)(val, extras);
|
|
79
|
-
const buttonHeight = buttonStyle?.height;
|
|
80
|
-
const fontStyle = (0, import_get_font_sized.getFontSized)(val, extras);
|
|
81
|
-
return {
|
|
82
|
-
...fontStyle,
|
|
83
|
-
lineHeight: buttonHeight ? extras.tokens.size[buttonHeight] : void 0
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
defaultVariants: {
|
|
89
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
90
|
-
}
|
|
59
|
+
displayName: "Label",
|
|
60
|
+
render: "label",
|
|
61
|
+
size: true,
|
|
62
|
+
backgroundColor: "transparent",
|
|
63
|
+
display: "flex",
|
|
64
|
+
alignItems: "center",
|
|
65
|
+
userSelect: "none",
|
|
66
|
+
cursor: "default",
|
|
67
|
+
variants: { size: {
|
|
68
|
+
true: labelSizeVariant,
|
|
69
|
+
Size: labelSizeVariant
|
|
70
|
+
} }
|
|
91
71
|
});
|
|
92
|
-
const Label =
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
});
|
|
72
|
+
const Label = (0, import_web.createStyledHOC)(LabelFrame, function Label2(props, forwardedRef) {
|
|
73
|
+
const { htmlFor, id: idProp, ...labelProps } = props;
|
|
74
|
+
const controlRef = React.useRef(null);
|
|
75
|
+
const ref = React.useRef(null);
|
|
76
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
77
|
+
const backupId = React.useId();
|
|
78
|
+
const id = idProp ?? backupId;
|
|
79
|
+
if (import_constants.isWeb) {
|
|
80
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
81
|
+
if (htmlFor) {
|
|
82
|
+
const element = document.getElementById(htmlFor);
|
|
83
|
+
const label = ref.current;
|
|
84
|
+
if (label && element) {
|
|
85
|
+
const getAriaLabel = () => element.getAttribute("aria-labelledby");
|
|
86
|
+
const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(" ");
|
|
87
|
+
element.setAttribute("aria-labelledby", ariaLabelledBy);
|
|
88
|
+
controlRef.current = element;
|
|
89
|
+
return () => {
|
|
90
|
+
if (!id) return;
|
|
91
|
+
const ariaLabelledBy2 = getAriaLabel()?.replace(id, "");
|
|
92
|
+
if (ariaLabelledBy2 === "") {
|
|
93
|
+
element.removeAttribute("aria-labelledby");
|
|
94
|
+
} else if (ariaLabelledBy2) {
|
|
95
|
+
element.setAttribute("aria-labelledby", ariaLabelledBy2);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}, [id, htmlFor]);
|
|
101
|
+
}
|
|
102
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LabelProvider, {
|
|
103
|
+
id,
|
|
104
|
+
controlRef,
|
|
105
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LabelFrame, {
|
|
106
|
+
id,
|
|
107
|
+
htmlFor,
|
|
108
|
+
...labelProps,
|
|
109
|
+
ref: composedRefs,
|
|
110
|
+
onMouseDown: (event) => {
|
|
111
|
+
props.onMouseDown?.(event);
|
|
112
|
+
if (!event.defaultPrevented && event.detail > 1) {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
onPress: (event) => {
|
|
117
|
+
props.onPress?.(event);
|
|
118
|
+
if (import_constants.isWeb) {
|
|
119
|
+
if (htmlFor || !controlRef.current || event.defaultPrevented) return;
|
|
120
|
+
const isClickingControl = controlRef.current.contains(event.target);
|
|
121
|
+
const isUserClick = event.isTrusted === true;
|
|
122
|
+
if (!isClickingControl && isUserClick) {
|
|
123
|
+
controlRef.current.click();
|
|
124
|
+
controlRef.current.focus();
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
if (props.htmlFor) {
|
|
128
|
+
(0, import_focusable.focusFocusable)(props.htmlFor);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
});
|
|
158
134
|
});
|
|
159
|
-
const useLabelContext = element => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return context.id;
|
|
168
|
-
};
|
|
135
|
+
const useLabelContext = (element) => {
|
|
136
|
+
const context = useLabelContextImpl("LabelConsumer");
|
|
137
|
+
const { controlRef } = context;
|
|
138
|
+
React.useEffect(() => {
|
|
139
|
+
if (element) controlRef.current = element;
|
|
140
|
+
}, [element, controlRef]);
|
|
141
|
+
return context.id;
|
|
142
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var Label_exports = {};
|
|
31
|
+
__export(Label_exports, {
|
|
32
|
+
Label: () => Label,
|
|
33
|
+
LabelFrame: () => LabelFrame,
|
|
34
|
+
useLabelContext: () => useLabelContext
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(Label_exports);
|
|
37
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
38
|
+
var import_compose_refs = require("@tamagui/compose-refs");
|
|
39
|
+
var import_constants = require("@tamagui/constants");
|
|
40
|
+
var import_create_context = require("@tamagui/create-context");
|
|
41
|
+
var import_focusable = require("@tamagui/focusable");
|
|
42
|
+
var import_get_font_sized = require("@tamagui/get-font-sized");
|
|
43
|
+
var import_size = require("@tamagui/size");
|
|
44
|
+
var import_text = require("@tamagui/text");
|
|
45
|
+
var import_web = require("@tamagui/web");
|
|
46
|
+
var React = __toESM(require("react"), 1);
|
|
47
|
+
var NAME = "Label";
|
|
48
|
+
var [LabelProvider, useLabelContextImpl] = (0, import_create_context.createContext)(NAME, {
|
|
49
|
+
id: void 0,
|
|
50
|
+
controlRef: { current: null }
|
|
51
|
+
});
|
|
52
|
+
var labelSizeVariant = function(val, extras) {
|
|
53
|
+
var fontStyle = (0, import_get_font_sized.getFontSized)(val, extras);
|
|
54
|
+
var sizeKey = (0, import_size.resolveSizeToken)(val, "size");
|
|
55
|
+
return {
|
|
56
|
+
...fontStyle,
|
|
57
|
+
lineHeight: typeof sizeKey === "number" ? sizeKey : extras.tokens.size[sizeKey]
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
var LabelFrame = (0, import_web.styled)(import_text.SizableText, {
|
|
61
|
+
displayName: "Label",
|
|
62
|
+
render: "label",
|
|
63
|
+
size: true,
|
|
64
|
+
backgroundColor: "transparent",
|
|
65
|
+
display: "flex",
|
|
66
|
+
alignItems: "center",
|
|
67
|
+
userSelect: "none",
|
|
68
|
+
cursor: "default",
|
|
69
|
+
variants: { size: {
|
|
70
|
+
true: labelSizeVariant,
|
|
71
|
+
Size: labelSizeVariant
|
|
72
|
+
} }
|
|
73
|
+
});
|
|
74
|
+
var Label = (0, import_web.createStyledHOC)(LabelFrame, function Label2(props, forwardedRef) {
|
|
75
|
+
var { htmlFor, id: idProp, ...labelProps } = props;
|
|
76
|
+
var controlRef = React.useRef(null);
|
|
77
|
+
var ref = React.useRef(null);
|
|
78
|
+
var composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
79
|
+
var backupId = React.useId();
|
|
80
|
+
var id = idProp !== null && idProp !== void 0 ? idProp : backupId;
|
|
81
|
+
if (import_constants.isWeb) {
|
|
82
|
+
(0, import_constants.useIsomorphicLayoutEffect)(function() {
|
|
83
|
+
if (htmlFor) {
|
|
84
|
+
var element = document.getElementById(htmlFor);
|
|
85
|
+
var label = ref.current;
|
|
86
|
+
if (label && element) {
|
|
87
|
+
var getAriaLabel = function() {
|
|
88
|
+
return element.getAttribute("aria-labelledby");
|
|
89
|
+
};
|
|
90
|
+
var ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(" ");
|
|
91
|
+
element.setAttribute("aria-labelledby", ariaLabelledBy);
|
|
92
|
+
controlRef.current = element;
|
|
93
|
+
return function() {
|
|
94
|
+
var _getAriaLabel;
|
|
95
|
+
if (!id) return;
|
|
96
|
+
var ariaLabelledBy2 = (_getAriaLabel = getAriaLabel()) === null || _getAriaLabel === void 0 ? void 0 : _getAriaLabel.replace(id, "");
|
|
97
|
+
if (ariaLabelledBy2 === "") {
|
|
98
|
+
element.removeAttribute("aria-labelledby");
|
|
99
|
+
} else if (ariaLabelledBy2) {
|
|
100
|
+
element.setAttribute("aria-labelledby", ariaLabelledBy2);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, [id, htmlFor]);
|
|
106
|
+
}
|
|
107
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LabelProvider, {
|
|
108
|
+
id,
|
|
109
|
+
controlRef,
|
|
110
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LabelFrame, {
|
|
111
|
+
id,
|
|
112
|
+
htmlFor,
|
|
113
|
+
...labelProps,
|
|
114
|
+
ref: composedRefs,
|
|
115
|
+
onMouseDown: function(event) {
|
|
116
|
+
var _props_onMouseDown;
|
|
117
|
+
(_props_onMouseDown = props.onMouseDown) === null || _props_onMouseDown === void 0 ? void 0 : _props_onMouseDown.call(props, event);
|
|
118
|
+
if (!event.defaultPrevented && event.detail > 1) {
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
onPress: function(event) {
|
|
123
|
+
var _props_onPress;
|
|
124
|
+
(_props_onPress = props.onPress) === null || _props_onPress === void 0 ? void 0 : _props_onPress.call(props, event);
|
|
125
|
+
if (import_constants.isWeb) {
|
|
126
|
+
if (htmlFor || !controlRef.current || event.defaultPrevented) return;
|
|
127
|
+
var isClickingControl = controlRef.current.contains(event.target);
|
|
128
|
+
var isUserClick = event.isTrusted === true;
|
|
129
|
+
if (!isClickingControl && isUserClick) {
|
|
130
|
+
controlRef.current.click();
|
|
131
|
+
controlRef.current.focus();
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
if (props.htmlFor) {
|
|
135
|
+
(0, import_focusable.focusFocusable)(props.htmlFor);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
var useLabelContext = function(element) {
|
|
143
|
+
var context = useLabelContextImpl("LabelConsumer");
|
|
144
|
+
var { controlRef } = context;
|
|
145
|
+
React.useEffect(function() {
|
|
146
|
+
if (element) controlRef.current = element;
|
|
147
|
+
}, [element, controlRef]);
|
|
148
|
+
return context.id;
|
|
149
|
+
};
|