@tamagui/label 1.0.1-beta.103
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/Card.js +144 -0
- package/dist/cjs/Card.js.map +7 -0
- package/dist/cjs/Label.js +178 -0
- package/dist/cjs/Label.js.map +7 -0
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/esm/Card.js +119 -0
- package/dist/esm/Card.js.map +7 -0
- package/dist/esm/Label.js +159 -0
- package/dist/esm/Label.js.map +7 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/jsx/Card.js +87 -0
- package/dist/jsx/Card.js.map +7 -0
- package/dist/jsx/Label.js +119 -0
- package/dist/jsx/Label.js.map +7 -0
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/index.js.map +7 -0
- package/package.json +45 -0
- package/src/Label.tsx +157 -0
- package/src/index.ts +1 -0
- package/types/Label.d.ts +25 -0
- package/types/Label.d.ts.map +1 -0
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -0
package/dist/cjs/Card.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
var __export = (target, all) => {
|
|
34
|
+
for (var name in all)
|
|
35
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
36
|
+
};
|
|
37
|
+
var __copyProps = (to, from, except, desc) => {
|
|
38
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
39
|
+
for (let key of __getOwnPropNames(from))
|
|
40
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
41
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
42
|
+
}
|
|
43
|
+
return to;
|
|
44
|
+
};
|
|
45
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
46
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
47
|
+
var Card_exports = {};
|
|
48
|
+
__export(Card_exports, {
|
|
49
|
+
Card: () => Card,
|
|
50
|
+
CardBackground: () => CardBackground,
|
|
51
|
+
CardFooter: () => CardFooter,
|
|
52
|
+
CardFrame: () => CardFrame,
|
|
53
|
+
CardHeader: () => CardHeader,
|
|
54
|
+
createCardScope: () => createCardScope,
|
|
55
|
+
useCardContext: () => useCardContext
|
|
56
|
+
});
|
|
57
|
+
module.exports = __toCommonJS(Card_exports);
|
|
58
|
+
var import_core = require("@tamagui/core");
|
|
59
|
+
var import_create_context = require("@tamagui/create-context");
|
|
60
|
+
var import_stacks = require("@tamagui/stacks");
|
|
61
|
+
var import_react = __toESM(require("react"));
|
|
62
|
+
import_react.default["createElement"];
|
|
63
|
+
const CARD_NAME = "CARD";
|
|
64
|
+
const [createCardContext, createCardScope] = (0, import_create_context.createContextScope)(CARD_NAME);
|
|
65
|
+
const [CardProvider, useCardContext] = createCardContext(CARD_NAME);
|
|
66
|
+
const CardFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
67
|
+
name: "Card",
|
|
68
|
+
backgroundColor: "$background",
|
|
69
|
+
position: "relative",
|
|
70
|
+
overflow: "hidden",
|
|
71
|
+
variants: {
|
|
72
|
+
size: {
|
|
73
|
+
"...size": (val, { tokens }) => {
|
|
74
|
+
return {
|
|
75
|
+
borderRadius: tokens.radius[val] ?? val
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
defaultVariants: {
|
|
81
|
+
size: "$4"
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const CardHeader = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
85
|
+
name: "CardHeader",
|
|
86
|
+
zIndex: 10,
|
|
87
|
+
backgroundColor: "transparent",
|
|
88
|
+
marginBottom: "auto",
|
|
89
|
+
variants: {
|
|
90
|
+
size: {
|
|
91
|
+
"...size": (val, { tokens }) => {
|
|
92
|
+
return {
|
|
93
|
+
padding: tokens.space[val] ?? val
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
const CardFooter = (0, import_core.styled)(CardHeader, {
|
|
100
|
+
name: "CardFooter",
|
|
101
|
+
zIndex: 5,
|
|
102
|
+
flexDirection: "row",
|
|
103
|
+
marginTop: "auto",
|
|
104
|
+
marginBottom: 0
|
|
105
|
+
});
|
|
106
|
+
const CardBackground = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
107
|
+
name: "CardBackground",
|
|
108
|
+
zIndex: 0,
|
|
109
|
+
fullscreen: true,
|
|
110
|
+
overflow: "hidden",
|
|
111
|
+
pointerEvents: "none",
|
|
112
|
+
padding: 0
|
|
113
|
+
});
|
|
114
|
+
const Card = (0, import_core.withStaticProperties)(CardFrame.extractable((0, import_core.themeable)((0, import_react.forwardRef)((_a, ref) => {
|
|
115
|
+
var _b = _a, { size, __scopeCard, children } = _b, props = __objRest(_b, ["size", "__scopeCard", "children"]);
|
|
116
|
+
return /* @__PURE__ */ import_react.default.createElement(CardProvider, {
|
|
117
|
+
scope: __scopeCard,
|
|
118
|
+
size
|
|
119
|
+
}, /* @__PURE__ */ import_react.default.createElement(CardFrame, __spreadValues({
|
|
120
|
+
ref
|
|
121
|
+
}, props), import_react.default.Children.map(children, (child) => {
|
|
122
|
+
if ((0, import_core.isTamaguiElement)(child) && !child.props.size) {
|
|
123
|
+
return (0, import_react.cloneElement)(child, {
|
|
124
|
+
size
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return child;
|
|
128
|
+
})));
|
|
129
|
+
}))), {
|
|
130
|
+
Header: CardHeader,
|
|
131
|
+
Footer: CardFooter,
|
|
132
|
+
Background: CardBackground
|
|
133
|
+
});
|
|
134
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
135
|
+
0 && (module.exports = {
|
|
136
|
+
Card,
|
|
137
|
+
CardBackground,
|
|
138
|
+
CardFooter,
|
|
139
|
+
CardFrame,
|
|
140
|
+
CardHeader,
|
|
141
|
+
createCardScope,
|
|
142
|
+
useCardContext
|
|
143
|
+
});
|
|
144
|
+
//# sourceMappingURL=Card.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Card.tsx"],
|
|
4
|
+
"sourcesContent": ["import {\n GetProps,\n SizeTokens,\n isTamaguiElement,\n styled,\n themeable,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport React, { cloneElement, forwardRef } from 'react'\nimport { View } from 'react-native'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\nconst CARD_NAME = 'CARD'\n\ntype CardContextValue = {\n size?: SizeTokens\n}\n\nconst [createCardContext, createCardScope] = createContextScope(CARD_NAME)\nconst [CardProvider, useCardContext] = createCardContext<CardContextValue>(CARD_NAME)\n\nexport const CardFrame = styled(ThemeableStack, {\n name: 'Card',\n backgroundColor: '$background',\n position: 'relative',\n overflow: 'hidden',\n\n variants: {\n size: {\n '...size': (val, { tokens }) => {\n return {\n borderRadius: tokens.radius[val] ?? val,\n }\n },\n },\n },\n\n defaultVariants: {\n size: '$4',\n },\n})\n\nexport const CardHeader = styled(ThemeableStack, {\n name: 'CardHeader',\n zIndex: 10,\n backgroundColor: 'transparent',\n marginBottom: 'auto',\n\n variants: {\n size: {\n '...size': (val, { tokens }) => {\n return {\n padding: tokens.space[val] ?? val,\n }\n },\n },\n },\n})\n\nexport const CardFooter = styled(CardHeader, {\n name: 'CardFooter',\n zIndex: 5,\n flexDirection: 'row',\n marginTop: 'auto',\n marginBottom: 0,\n})\n\nexport const CardBackground = styled(ThemeableStack, {\n name: 'CardBackground',\n zIndex: 0,\n fullscreen: true,\n overflow: 'hidden',\n pointerEvents: 'none',\n padding: 0,\n})\n\nexport type CardHeaderProps = GetProps<typeof CardHeader>\nexport type CardFooterProps = GetProps<typeof CardFooter>\n\nexport type CardProps = GetProps<typeof CardFrame>\n\nexport const Card = withStaticProperties(\n CardFrame.extractable(\n themeable(\n forwardRef<HTMLElement | View, ScopedProps<CardProps, 'Card'>>(\n ({ size, __scopeCard, children, ...props }, ref) => {\n return (\n <CardProvider scope={__scopeCard} size={size}>\n <CardFrame ref={ref} {...props}>\n {React.Children.map(children, (child) => {\n if (isTamaguiElement(child) && !child.props.size) {\n return cloneElement(child, {\n size,\n })\n }\n return child\n })}\n </CardFrame>\n </CardProvider>\n )\n }\n )\n )\n ),\n {\n Header: CardHeader,\n Footer: CardFooter,\n Background: CardBackground,\n }\n)\n\nexport { createCardScope, useCardContext }\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAOO;AACP,4BAAgD;AAChD,oBAA+B;AAC/B,mBAAgD;AAIhD,qBAAM;AAEN,MAAM,YAAY;AAMlB,MAAM,CAAC,mBAAmB,mBAAmB,8CAAmB,SAAS;AACzE,MAAM,CAAC,cAAc,kBAAkB,kBAAoC,SAAS;AAE7E,MAAM,YAAY,wBAAO,8BAAgB;AAAA,EAC9C,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,UAAU;AAAA,EACV,UAAU;AAAA,EAEV,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW,CAAC,KAAK,EAAE,aAAa;AAC9B,eAAO;AAAA,UACL,cAAc,OAAO,OAAO,QAAQ;AAAA,QACtC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IACf,MAAM;AAAA,EACR;AACF,CAAC;AAEM,MAAM,aAAa,wBAAO,8BAAgB;AAAA,EAC/C,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,iBAAiB;AAAA,EACjB,cAAc;AAAA,EAEd,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW,CAAC,KAAK,EAAE,aAAa;AAC9B,eAAO;AAAA,UACL,SAAS,OAAO,MAAM,QAAQ;AAAA,QAChC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAEM,MAAM,aAAa,wBAAO,YAAY;AAAA,EAC3C,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,eAAe;AAAA,EACf,WAAW;AAAA,EACX,cAAc;AAChB,CAAC;AAEM,MAAM,iBAAiB,wBAAO,8BAAgB;AAAA,EACnD,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,eAAe;AAAA,EACf,SAAS;AACX,CAAC;AAOM,MAAM,OAAO,sCAClB,UAAU,YACR,2BACE,6BACE,CAAC,IAA2C,QAAQ;AAAnD,eAAE,QAAM,aAAa,aAArB,IAAkC,kBAAlC,IAAkC,CAAhC,QAAM,eAAa;AACpB,SACE,mDAAC;AAAA,IAAa,OAAO;AAAA,IAAa;AAAA,KAChC,mDAAC;AAAA,IAAU;AAAA,KAAc,QACtB,qBAAM,SAAS,IAAI,UAAU,CAAC,UAAU;AACvC,QAAI,kCAAiB,KAAK,KAAK,CAAC,MAAM,MAAM,MAAM;AAChD,aAAO,+BAAa,OAAO;AAAA,QACzB;AAAA,MACF,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT,CAAC,CACH,CACF;AAEJ,CACF,CACF,CACF,GACA;AAAA,EACE,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,YAAY;AACd,CACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __objRest = (source, exclude) => {
|
|
25
|
+
var target = {};
|
|
26
|
+
for (var prop in source)
|
|
27
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
if (source != null && __getOwnPropSymbols)
|
|
30
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
+
target[prop] = source[prop];
|
|
33
|
+
}
|
|
34
|
+
return target;
|
|
35
|
+
};
|
|
36
|
+
var __export = (target, all) => {
|
|
37
|
+
for (var name in all)
|
|
38
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
39
|
+
};
|
|
40
|
+
var __copyProps = (to, from, except, desc) => {
|
|
41
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
42
|
+
for (let key of __getOwnPropNames(from))
|
|
43
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
44
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
45
|
+
}
|
|
46
|
+
return to;
|
|
47
|
+
};
|
|
48
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
49
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
50
|
+
var Label_exports = {};
|
|
51
|
+
__export(Label_exports, {
|
|
52
|
+
Label: () => Label,
|
|
53
|
+
LabelFrame: () => LabelFrame,
|
|
54
|
+
useLabelContext: () => useLabelContext
|
|
55
|
+
});
|
|
56
|
+
module.exports = __toCommonJS(Label_exports);
|
|
57
|
+
var import_compose_refs = require("@tamagui/compose-refs");
|
|
58
|
+
var import_core = require("@tamagui/core");
|
|
59
|
+
var import_create_context = require("@tamagui/create-context");
|
|
60
|
+
var import_focusable = require("@tamagui/focusable");
|
|
61
|
+
var import_text = require("@tamagui/text");
|
|
62
|
+
var React = __toESM(require("react"));
|
|
63
|
+
const NAME = "Label";
|
|
64
|
+
const [LabelProvider, useLabelContextImpl] = (0, import_create_context.createContext)(NAME, {
|
|
65
|
+
id: void 0,
|
|
66
|
+
controlRef: { current: null }
|
|
67
|
+
});
|
|
68
|
+
const LabelFrame = (0, import_core.styled)(import_text.SizableText, {
|
|
69
|
+
name: "Label",
|
|
70
|
+
tag: "label",
|
|
71
|
+
size: "$4",
|
|
72
|
+
backgroundColor: "transparent",
|
|
73
|
+
display: "flex",
|
|
74
|
+
alignItems: "center",
|
|
75
|
+
selectable: false,
|
|
76
|
+
cursor: "default",
|
|
77
|
+
pressStyle: {
|
|
78
|
+
color: "$colorPress"
|
|
79
|
+
},
|
|
80
|
+
variants: {
|
|
81
|
+
size: {
|
|
82
|
+
"...size": (val, extras) => {
|
|
83
|
+
const buttonStyle = (0, import_core.getButtonSize)(val, extras);
|
|
84
|
+
return __spreadProps(__spreadValues({}, (0, import_core.getFont)(val, extras)), {
|
|
85
|
+
height: buttonStyle.height,
|
|
86
|
+
lineHeight: buttonStyle.height
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const LabelComponent = React.forwardRef((props, forwardedRef) => {
|
|
93
|
+
const _a = props, { htmlFor, id: idProp } = _a, labelProps = __objRest(_a, ["htmlFor", "id"]);
|
|
94
|
+
const controlRef = React.useRef(null);
|
|
95
|
+
const ref = React.useRef(null);
|
|
96
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
97
|
+
const id = (0, import_core.useId)(idProp);
|
|
98
|
+
if (import_core.isWeb) {
|
|
99
|
+
React.useEffect(() => {
|
|
100
|
+
if (htmlFor) {
|
|
101
|
+
const element = document.getElementById(htmlFor);
|
|
102
|
+
const label = ref.current;
|
|
103
|
+
if (label && element) {
|
|
104
|
+
const getAriaLabel = () => element.getAttribute("aria-labelledby");
|
|
105
|
+
const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(" ");
|
|
106
|
+
element.setAttribute("aria-labelledby", ariaLabelledBy);
|
|
107
|
+
controlRef.current = element;
|
|
108
|
+
return () => {
|
|
109
|
+
var _a2;
|
|
110
|
+
if (!id)
|
|
111
|
+
return;
|
|
112
|
+
const ariaLabelledBy2 = (_a2 = getAriaLabel()) == null ? void 0 : _a2.replace(id, "");
|
|
113
|
+
if (ariaLabelledBy2 === "") {
|
|
114
|
+
element.removeAttribute("aria-labelledby");
|
|
115
|
+
} else if (ariaLabelledBy2) {
|
|
116
|
+
element.setAttribute("aria-labelledby", ariaLabelledBy2);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}, [id, htmlFor]);
|
|
122
|
+
}
|
|
123
|
+
return /* @__PURE__ */ React.createElement(LabelProvider, {
|
|
124
|
+
id,
|
|
125
|
+
controlRef
|
|
126
|
+
}, /* @__PURE__ */ React.createElement(LabelFrame, __spreadProps(__spreadValues({
|
|
127
|
+
role: "label",
|
|
128
|
+
id
|
|
129
|
+
}, labelProps), {
|
|
130
|
+
ref: composedRefs,
|
|
131
|
+
onMouseDown: (event) => {
|
|
132
|
+
var _a2;
|
|
133
|
+
(_a2 = props.onMouseDown) == null ? void 0 : _a2.call(props, event);
|
|
134
|
+
if (!event.defaultPrevented && event.detail > 1) {
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
onPress: (event) => {
|
|
139
|
+
var _a2;
|
|
140
|
+
(_a2 = props.onPress) == null ? void 0 : _a2.call(props, event);
|
|
141
|
+
if (import_core.isWeb) {
|
|
142
|
+
if (!controlRef.current || event.defaultPrevented)
|
|
143
|
+
return;
|
|
144
|
+
const isClickingControl = controlRef.current.contains(event.target);
|
|
145
|
+
const isUserClick = event.isTrusted === true;
|
|
146
|
+
if (!isClickingControl && isUserClick) {
|
|
147
|
+
controlRef.current.click();
|
|
148
|
+
controlRef.current.focus();
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
if (props.htmlFor) {
|
|
152
|
+
(0, import_focusable.focusFocusable)(props.htmlFor);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
})));
|
|
157
|
+
});
|
|
158
|
+
LabelComponent.displayName = NAME;
|
|
159
|
+
const Label = LabelFrame.extractable((0, import_core.themeable)(LabelComponent), {
|
|
160
|
+
neverFlatten: true
|
|
161
|
+
});
|
|
162
|
+
const useLabelContext = (element) => {
|
|
163
|
+
const context = useLabelContextImpl("LabelConsumer");
|
|
164
|
+
const { controlRef } = context;
|
|
165
|
+
React.useEffect(() => {
|
|
166
|
+
if (element)
|
|
167
|
+
controlRef.current = element;
|
|
168
|
+
}, [element, controlRef]);
|
|
169
|
+
return context.id;
|
|
170
|
+
};
|
|
171
|
+
const Root = Label;
|
|
172
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
173
|
+
0 && (module.exports = {
|
|
174
|
+
Label,
|
|
175
|
+
LabelFrame,
|
|
176
|
+
useLabelContext
|
|
177
|
+
});
|
|
178
|
+
//# sourceMappingURL=Label.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Label.tsx"],
|
|
4
|
+
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n ReactComponentWithRef,\n getButtonSize,\n getFont,\n isWeb,\n styled,\n themeable,\n useId,\n} from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { SizableText } from '@tamagui/text'\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 size: '$4',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n selectable: false,\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSize(val, extras)\n return {\n ...getFont(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n },\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>((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 id = useId(idProp)\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 // @ts-ignore\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) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (!controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(event.target as any 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 } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAgC;AAChC,kBASO;AACP,4BAA8B;AAC9B,uBAA+B;AAC/B,kBAA4B;AAC5B,YAAuB;AAGvB,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,uBAAuB,yCAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,aAAa,wBAAO,yBAAa;AAAA,EAC5C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,YAAY;AAAA,IACV,OAAO;AAAA,EACT;AAAA,EACA,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,WAAW,CAAC,KAAK,WAAW;AAC1B,cAAM,cAAc,+BAAc,KAAK,MAAM;AAC7C,eAAO,iCACF,yBAAQ,KAAK,MAAM,IADjB;AAAA,UAEL,QAAQ,YAAY;AAAA,UACpB,YAAY,YAAY;AAAA,QAC1B;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAMD,MAAM,iBAAiB,MAAM,WAA0C,CAAC,OAAO,iBAAiB;AAC9F,QAA+C,YAAvC,WAAS,IAAI,WAA0B,IAAf,uBAAe,IAAf,CAAxB,WAAS;AACjB,QAAM,aAAa,MAAM,OAA2B,IAAI;AACxD,QAAM,MAAM,MAAM,OAAY,IAAI;AAClC,QAAM,eAAe,yCAAgB,cAAc,GAAG;AACtD,QAAM,KAAK,uBAAM,MAAM;AAEvB,MAAI,mBAAO;AACT,UAAM,UAAU,MAAM;AACpB,UAAI,SAAS;AACX,c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ACjB,+CAAe,MAAM,OAAO;AAAA,QAC9B;AAAA,MACF;AAAA,IACF;AAAA,IACF,CACF;AAEJ,CAAC;AAED,eAAe,cAAc;AAEtB,MAAM,QACX,WAAW,YAAY,2BAAU,cAAqB,GAAU;AAAA,EAC9D,cAAc;AAChB,CAAC;AAEI,MAAM,kBAAkB,CAAC,YAAiC;AAC/D,QAAM,UAAU,oBAAoB,eAAe;AACnD,QAAM,EAAE,eAAe;AAEvB,QAAM,UAAU,MAAM;AACpB,QAAI;AAAS,iBAAW,UAAU;AAAA,EACpC,GAAG,CAAC,SAAS,UAAU,CAAC;AAExB,SAAO,QAAQ;AACjB;AAEA,MAAM,OAAO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var src_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(src_exports);
|
|
17
|
+
__reExport(src_exports, require("./Label"), module.exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
package/dist/esm/Card.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __objRest = (source, exclude) => {
|
|
18
|
+
var target = {};
|
|
19
|
+
for (var prop in source)
|
|
20
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
21
|
+
target[prop] = source[prop];
|
|
22
|
+
if (source != null && __getOwnPropSymbols)
|
|
23
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
24
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
};
|
|
29
|
+
import {
|
|
30
|
+
isTamaguiElement,
|
|
31
|
+
styled,
|
|
32
|
+
themeable,
|
|
33
|
+
withStaticProperties
|
|
34
|
+
} from "@tamagui/core";
|
|
35
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
36
|
+
import { ThemeableStack } from "@tamagui/stacks";
|
|
37
|
+
import React, { cloneElement, forwardRef } from "react";
|
|
38
|
+
React["createElement"];
|
|
39
|
+
const CARD_NAME = "CARD";
|
|
40
|
+
const [createCardContext, createCardScope] = createContextScope(CARD_NAME);
|
|
41
|
+
const [CardProvider, useCardContext] = createCardContext(CARD_NAME);
|
|
42
|
+
const CardFrame = styled(ThemeableStack, {
|
|
43
|
+
name: "Card",
|
|
44
|
+
backgroundColor: "$background",
|
|
45
|
+
position: "relative",
|
|
46
|
+
overflow: "hidden",
|
|
47
|
+
variants: {
|
|
48
|
+
size: {
|
|
49
|
+
"...size": (val, { tokens }) => {
|
|
50
|
+
return {
|
|
51
|
+
borderRadius: tokens.radius[val] ?? val
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
defaultVariants: {
|
|
57
|
+
size: "$4"
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const CardHeader = styled(ThemeableStack, {
|
|
61
|
+
name: "CardHeader",
|
|
62
|
+
zIndex: 10,
|
|
63
|
+
backgroundColor: "transparent",
|
|
64
|
+
marginBottom: "auto",
|
|
65
|
+
variants: {
|
|
66
|
+
size: {
|
|
67
|
+
"...size": (val, { tokens }) => {
|
|
68
|
+
return {
|
|
69
|
+
padding: tokens.space[val] ?? val
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const CardFooter = styled(CardHeader, {
|
|
76
|
+
name: "CardFooter",
|
|
77
|
+
zIndex: 5,
|
|
78
|
+
flexDirection: "row",
|
|
79
|
+
marginTop: "auto",
|
|
80
|
+
marginBottom: 0
|
|
81
|
+
});
|
|
82
|
+
const CardBackground = styled(ThemeableStack, {
|
|
83
|
+
name: "CardBackground",
|
|
84
|
+
zIndex: 0,
|
|
85
|
+
fullscreen: true,
|
|
86
|
+
overflow: "hidden",
|
|
87
|
+
pointerEvents: "none",
|
|
88
|
+
padding: 0
|
|
89
|
+
});
|
|
90
|
+
const Card = withStaticProperties(CardFrame.extractable(themeable(forwardRef((_a, ref) => {
|
|
91
|
+
var _b = _a, { size, __scopeCard, children } = _b, props = __objRest(_b, ["size", "__scopeCard", "children"]);
|
|
92
|
+
return /* @__PURE__ */ React.createElement(CardProvider, {
|
|
93
|
+
scope: __scopeCard,
|
|
94
|
+
size
|
|
95
|
+
}, /* @__PURE__ */ React.createElement(CardFrame, __spreadValues({
|
|
96
|
+
ref
|
|
97
|
+
}, props), React.Children.map(children, (child) => {
|
|
98
|
+
if (isTamaguiElement(child) && !child.props.size) {
|
|
99
|
+
return cloneElement(child, {
|
|
100
|
+
size
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return child;
|
|
104
|
+
})));
|
|
105
|
+
}))), {
|
|
106
|
+
Header: CardHeader,
|
|
107
|
+
Footer: CardFooter,
|
|
108
|
+
Background: CardBackground
|
|
109
|
+
});
|
|
110
|
+
export {
|
|
111
|
+
Card,
|
|
112
|
+
CardBackground,
|
|
113
|
+
CardFooter,
|
|
114
|
+
CardFrame,
|
|
115
|
+
CardHeader,
|
|
116
|
+
createCardScope,
|
|
117
|
+
useCardContext
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=Card.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Card.tsx"],
|
|
4
|
+
"sourcesContent": ["import {\n GetProps,\n SizeTokens,\n isTamaguiElement,\n styled,\n themeable,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport React, { cloneElement, forwardRef } from 'react'\nimport { View } from 'react-native'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\nconst CARD_NAME = 'CARD'\n\ntype CardContextValue = {\n size?: SizeTokens\n}\n\nconst [createCardContext, createCardScope] = createContextScope(CARD_NAME)\nconst [CardProvider, useCardContext] = createCardContext<CardContextValue>(CARD_NAME)\n\nexport const CardFrame = styled(ThemeableStack, {\n name: 'Card',\n backgroundColor: '$background',\n position: 'relative',\n overflow: 'hidden',\n\n variants: {\n size: {\n '...size': (val, { tokens }) => {\n return {\n borderRadius: tokens.radius[val] ?? val,\n }\n },\n },\n },\n\n defaultVariants: {\n size: '$4',\n },\n})\n\nexport const CardHeader = styled(ThemeableStack, {\n name: 'CardHeader',\n zIndex: 10,\n backgroundColor: 'transparent',\n marginBottom: 'auto',\n\n variants: {\n size: {\n '...size': (val, { tokens }) => {\n return {\n padding: tokens.space[val] ?? val,\n }\n },\n },\n },\n})\n\nexport const CardFooter = styled(CardHeader, {\n name: 'CardFooter',\n zIndex: 5,\n flexDirection: 'row',\n marginTop: 'auto',\n marginBottom: 0,\n})\n\nexport const CardBackground = styled(ThemeableStack, {\n name: 'CardBackground',\n zIndex: 0,\n fullscreen: true,\n overflow: 'hidden',\n pointerEvents: 'none',\n padding: 0,\n})\n\nexport type CardHeaderProps = GetProps<typeof CardHeader>\nexport type CardFooterProps = GetProps<typeof CardFooter>\n\nexport type CardProps = GetProps<typeof CardFrame>\n\nexport const Card = withStaticProperties(\n CardFrame.extractable(\n themeable(\n forwardRef<HTMLElement | View, ScopedProps<CardProps, 'Card'>>(\n ({ size, __scopeCard, children, ...props }, ref) => {\n return (\n <CardProvider scope={__scopeCard} size={size}>\n <CardFrame ref={ref} {...props}>\n {React.Children.map(children, (child) => {\n if (isTamaguiElement(child) && !child.props.size) {\n return cloneElement(child, {\n size,\n })\n }\n return child\n })}\n </CardFrame>\n </CardProvider>\n )\n }\n )\n )\n ),\n {\n Header: CardHeader,\n Footer: CardFooter,\n Background: CardBackground,\n }\n)\n\nexport { createCardScope, useCardContext }\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA;AACA;AACA;AAIA,MAAM;AAEN,MAAM,YAAY;AAMlB,MAAM,CAAC,mBAAmB,mBAAmB,mBAAmB,SAAS;AACzE,MAAM,CAAC,cAAc,kBAAkB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,MAAM,MAAM,MAAM;AAChD,aAAO,aAAa,OAAO;AAAA,QACzB;AAAA,MACF,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT,CAAC,CACH,CACF;AAEJ,CACF,CACF,CACF,GACA;AAAA,EACE,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,YAAY;AACd,CACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
33
|
+
import {
|
|
34
|
+
getButtonSize,
|
|
35
|
+
getFont,
|
|
36
|
+
isWeb,
|
|
37
|
+
styled,
|
|
38
|
+
themeable,
|
|
39
|
+
useId
|
|
40
|
+
} from "@tamagui/core";
|
|
41
|
+
import { createContext } from "@tamagui/create-context";
|
|
42
|
+
import { focusFocusable } from "@tamagui/focusable";
|
|
43
|
+
import { SizableText } from "@tamagui/text";
|
|
44
|
+
import * as React from "react";
|
|
45
|
+
const NAME = "Label";
|
|
46
|
+
const [LabelProvider, useLabelContextImpl] = createContext(NAME, {
|
|
47
|
+
id: void 0,
|
|
48
|
+
controlRef: { current: null }
|
|
49
|
+
});
|
|
50
|
+
const LabelFrame = styled(SizableText, {
|
|
51
|
+
name: "Label",
|
|
52
|
+
tag: "label",
|
|
53
|
+
size: "$4",
|
|
54
|
+
backgroundColor: "transparent",
|
|
55
|
+
display: "flex",
|
|
56
|
+
alignItems: "center",
|
|
57
|
+
selectable: false,
|
|
58
|
+
cursor: "default",
|
|
59
|
+
pressStyle: {
|
|
60
|
+
color: "$colorPress"
|
|
61
|
+
},
|
|
62
|
+
variants: {
|
|
63
|
+
size: {
|
|
64
|
+
"...size": (val, extras) => {
|
|
65
|
+
const buttonStyle = getButtonSize(val, extras);
|
|
66
|
+
return __spreadProps(__spreadValues({}, getFont(val, extras)), {
|
|
67
|
+
height: buttonStyle.height,
|
|
68
|
+
lineHeight: buttonStyle.height
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
const LabelComponent = React.forwardRef((props, forwardedRef) => {
|
|
75
|
+
const _a = props, { htmlFor, id: idProp } = _a, labelProps = __objRest(_a, ["htmlFor", "id"]);
|
|
76
|
+
const controlRef = React.useRef(null);
|
|
77
|
+
const ref = React.useRef(null);
|
|
78
|
+
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
79
|
+
const id = useId(idProp);
|
|
80
|
+
if (isWeb) {
|
|
81
|
+
React.useEffect(() => {
|
|
82
|
+
if (htmlFor) {
|
|
83
|
+
const element = document.getElementById(htmlFor);
|
|
84
|
+
const label = ref.current;
|
|
85
|
+
if (label && element) {
|
|
86
|
+
const getAriaLabel = () => element.getAttribute("aria-labelledby");
|
|
87
|
+
const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(" ");
|
|
88
|
+
element.setAttribute("aria-labelledby", ariaLabelledBy);
|
|
89
|
+
controlRef.current = element;
|
|
90
|
+
return () => {
|
|
91
|
+
var _a2;
|
|
92
|
+
if (!id)
|
|
93
|
+
return;
|
|
94
|
+
const ariaLabelledBy2 = (_a2 = getAriaLabel()) == null ? void 0 : _a2.replace(id, "");
|
|
95
|
+
if (ariaLabelledBy2 === "") {
|
|
96
|
+
element.removeAttribute("aria-labelledby");
|
|
97
|
+
} else if (ariaLabelledBy2) {
|
|
98
|
+
element.setAttribute("aria-labelledby", ariaLabelledBy2);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}, [id, htmlFor]);
|
|
104
|
+
}
|
|
105
|
+
return /* @__PURE__ */ React.createElement(LabelProvider, {
|
|
106
|
+
id,
|
|
107
|
+
controlRef
|
|
108
|
+
}, /* @__PURE__ */ React.createElement(LabelFrame, __spreadProps(__spreadValues({
|
|
109
|
+
role: "label",
|
|
110
|
+
id
|
|
111
|
+
}, labelProps), {
|
|
112
|
+
ref: composedRefs,
|
|
113
|
+
onMouseDown: (event) => {
|
|
114
|
+
var _a2;
|
|
115
|
+
(_a2 = props.onMouseDown) == null ? void 0 : _a2.call(props, event);
|
|
116
|
+
if (!event.defaultPrevented && event.detail > 1) {
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
onPress: (event) => {
|
|
121
|
+
var _a2;
|
|
122
|
+
(_a2 = props.onPress) == null ? void 0 : _a2.call(props, event);
|
|
123
|
+
if (isWeb) {
|
|
124
|
+
if (!controlRef.current || event.defaultPrevented)
|
|
125
|
+
return;
|
|
126
|
+
const isClickingControl = controlRef.current.contains(event.target);
|
|
127
|
+
const isUserClick = event.isTrusted === true;
|
|
128
|
+
if (!isClickingControl && isUserClick) {
|
|
129
|
+
controlRef.current.click();
|
|
130
|
+
controlRef.current.focus();
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
if (props.htmlFor) {
|
|
134
|
+
focusFocusable(props.htmlFor);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
})));
|
|
139
|
+
});
|
|
140
|
+
LabelComponent.displayName = NAME;
|
|
141
|
+
const Label = LabelFrame.extractable(themeable(LabelComponent), {
|
|
142
|
+
neverFlatten: true
|
|
143
|
+
});
|
|
144
|
+
const useLabelContext = (element) => {
|
|
145
|
+
const context = useLabelContextImpl("LabelConsumer");
|
|
146
|
+
const { controlRef } = context;
|
|
147
|
+
React.useEffect(() => {
|
|
148
|
+
if (element)
|
|
149
|
+
controlRef.current = element;
|
|
150
|
+
}, [element, controlRef]);
|
|
151
|
+
return context.id;
|
|
152
|
+
};
|
|
153
|
+
const Root = Label;
|
|
154
|
+
export {
|
|
155
|
+
Label,
|
|
156
|
+
LabelFrame,
|
|
157
|
+
useLabelContext
|
|
158
|
+
};
|
|
159
|
+
//# sourceMappingURL=Label.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Label.tsx"],
|
|
4
|
+
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n ReactComponentWithRef,\n getButtonSize,\n getFont,\n isWeb,\n styled,\n themeable,\n useId,\n} from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { SizableText } from '@tamagui/text'\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 size: '$4',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n selectable: false,\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSize(val, extras)\n return {\n ...getFont(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n },\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>((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 id = useId(idProp)\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 // @ts-ignore\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) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (!controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(event.target as any 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 } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\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;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA;AACA;AACA;AACA;AAGA,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,uBAAuB,cAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,aAAa,OAAO,aAAa;AAAA,EAC5C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,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import {
|
|
2
|
+
isTamaguiElement,
|
|
3
|
+
styled,
|
|
4
|
+
themeable,
|
|
5
|
+
withStaticProperties
|
|
6
|
+
} from "@tamagui/core";
|
|
7
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
8
|
+
import { ThemeableStack } from "@tamagui/stacks";
|
|
9
|
+
import React, { cloneElement, forwardRef } from "react";
|
|
10
|
+
React["createElement"];
|
|
11
|
+
const CARD_NAME = "CARD";
|
|
12
|
+
const [createCardContext, createCardScope] = createContextScope(CARD_NAME);
|
|
13
|
+
const [CardProvider, useCardContext] = createCardContext(CARD_NAME);
|
|
14
|
+
const CardFrame = styled(ThemeableStack, {
|
|
15
|
+
name: "Card",
|
|
16
|
+
backgroundColor: "$background",
|
|
17
|
+
position: "relative",
|
|
18
|
+
overflow: "hidden",
|
|
19
|
+
variants: {
|
|
20
|
+
size: {
|
|
21
|
+
"...size": (val, { tokens }) => {
|
|
22
|
+
var _a;
|
|
23
|
+
return {
|
|
24
|
+
borderRadius: (_a = tokens.radius[val]) != null ? _a : val
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
defaultVariants: {
|
|
30
|
+
size: "$4"
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const CardHeader = styled(ThemeableStack, {
|
|
34
|
+
name: "CardHeader",
|
|
35
|
+
zIndex: 10,
|
|
36
|
+
backgroundColor: "transparent",
|
|
37
|
+
marginBottom: "auto",
|
|
38
|
+
variants: {
|
|
39
|
+
size: {
|
|
40
|
+
"...size": (val, { tokens }) => {
|
|
41
|
+
var _a;
|
|
42
|
+
return {
|
|
43
|
+
padding: (_a = tokens.space[val]) != null ? _a : val
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const CardFooter = styled(CardHeader, {
|
|
50
|
+
name: "CardFooter",
|
|
51
|
+
zIndex: 5,
|
|
52
|
+
flexDirection: "row",
|
|
53
|
+
marginTop: "auto",
|
|
54
|
+
marginBottom: 0
|
|
55
|
+
});
|
|
56
|
+
const CardBackground = styled(ThemeableStack, {
|
|
57
|
+
name: "CardBackground",
|
|
58
|
+
zIndex: 0,
|
|
59
|
+
fullscreen: true,
|
|
60
|
+
overflow: "hidden",
|
|
61
|
+
pointerEvents: "none",
|
|
62
|
+
padding: 0
|
|
63
|
+
});
|
|
64
|
+
const Card = withStaticProperties(CardFrame.extractable(themeable(forwardRef(({ size, __scopeCard, children, ...props }, ref) => {
|
|
65
|
+
return <CardProvider scope={__scopeCard} size={size}><CardFrame ref={ref} {...props}>{React.Children.map(children, (child) => {
|
|
66
|
+
if (isTamaguiElement(child) && !child.props.size) {
|
|
67
|
+
return cloneElement(child, {
|
|
68
|
+
size
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return child;
|
|
72
|
+
})}</CardFrame></CardProvider>;
|
|
73
|
+
}))), {
|
|
74
|
+
Header: CardHeader,
|
|
75
|
+
Footer: CardFooter,
|
|
76
|
+
Background: CardBackground
|
|
77
|
+
});
|
|
78
|
+
export {
|
|
79
|
+
Card,
|
|
80
|
+
CardBackground,
|
|
81
|
+
CardFooter,
|
|
82
|
+
CardFrame,
|
|
83
|
+
CardHeader,
|
|
84
|
+
createCardScope,
|
|
85
|
+
useCardContext
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=Card.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Card.tsx"],
|
|
4
|
+
"sourcesContent": ["import {\n GetProps,\n SizeTokens,\n isTamaguiElement,\n styled,\n themeable,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport React, { cloneElement, forwardRef } from 'react'\nimport { View } from 'react-native'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\nconst CARD_NAME = 'CARD'\n\ntype CardContextValue = {\n size?: SizeTokens\n}\n\nconst [createCardContext, createCardScope] = createContextScope(CARD_NAME)\nconst [CardProvider, useCardContext] = createCardContext<CardContextValue>(CARD_NAME)\n\nexport const CardFrame = styled(ThemeableStack, {\n name: 'Card',\n backgroundColor: '$background',\n position: 'relative',\n overflow: 'hidden',\n\n variants: {\n size: {\n '...size': (val, { tokens }) => {\n return {\n borderRadius: tokens.radius[val] ?? val,\n }\n },\n },\n },\n\n defaultVariants: {\n size: '$4',\n },\n})\n\nexport const CardHeader = styled(ThemeableStack, {\n name: 'CardHeader',\n zIndex: 10,\n backgroundColor: 'transparent',\n marginBottom: 'auto',\n\n variants: {\n size: {\n '...size': (val, { tokens }) => {\n return {\n padding: tokens.space[val] ?? val,\n }\n },\n },\n },\n})\n\nexport const CardFooter = styled(CardHeader, {\n name: 'CardFooter',\n zIndex: 5,\n flexDirection: 'row',\n marginTop: 'auto',\n marginBottom: 0,\n})\n\nexport const CardBackground = styled(ThemeableStack, {\n name: 'CardBackground',\n zIndex: 0,\n fullscreen: true,\n overflow: 'hidden',\n pointerEvents: 'none',\n padding: 0,\n})\n\nexport type CardHeaderProps = GetProps<typeof CardHeader>\nexport type CardFooterProps = GetProps<typeof CardFooter>\n\nexport type CardProps = GetProps<typeof CardFrame>\n\nexport const Card = withStaticProperties(\n CardFrame.extractable(\n themeable(\n forwardRef<HTMLElement | View, ScopedProps<CardProps, 'Card'>>(\n ({ size, __scopeCard, children, ...props }, ref) => {\n return (\n <CardProvider scope={__scopeCard} size={size}>\n <CardFrame ref={ref} {...props}>\n {React.Children.map(children, (child) => {\n if (isTamaguiElement(child) && !child.props.size) {\n return cloneElement(child, {\n size,\n })\n }\n return child\n })}\n </CardFrame>\n </CardProvider>\n )\n }\n )\n )\n ),\n {\n Header: CardHeader,\n Footer: CardFooter,\n Background: CardBackground,\n }\n)\n\nexport { createCardScope, useCardContext }\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA;AAAA;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C,CAAC,UAAU,KAAK,SAAS,QACtB,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU;AACvC,QAAI,iBAAiB,KAAK,KAAK,CAAC,MAAM,MAAM,MAAM;AAChD,aAAO,aAAa,OAAO;AAAA,QACzB;AAAA,MACF,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT,CAAC,EACH,EATC,UAUH,EAXC;AAaL,CACF,CACF,CACF,GACA;AAAA,EACE,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,YAAY;AACd,CACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import {
|
|
3
|
+
getButtonSize,
|
|
4
|
+
getFont,
|
|
5
|
+
isWeb,
|
|
6
|
+
styled,
|
|
7
|
+
themeable,
|
|
8
|
+
useId
|
|
9
|
+
} from "@tamagui/core";
|
|
10
|
+
import { createContext } from "@tamagui/create-context";
|
|
11
|
+
import { focusFocusable } from "@tamagui/focusable";
|
|
12
|
+
import { SizableText } from "@tamagui/text";
|
|
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
|
+
size: "$4",
|
|
23
|
+
backgroundColor: "transparent",
|
|
24
|
+
display: "flex",
|
|
25
|
+
alignItems: "center",
|
|
26
|
+
selectable: false,
|
|
27
|
+
cursor: "default",
|
|
28
|
+
pressStyle: {
|
|
29
|
+
color: "$colorPress"
|
|
30
|
+
},
|
|
31
|
+
variants: {
|
|
32
|
+
size: {
|
|
33
|
+
"...size": (val, extras) => {
|
|
34
|
+
const buttonStyle = getButtonSize(val, extras);
|
|
35
|
+
return {
|
|
36
|
+
...getFont(val, extras),
|
|
37
|
+
height: buttonStyle.height,
|
|
38
|
+
lineHeight: buttonStyle.height
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const LabelComponent = React.forwardRef((props, forwardedRef) => {
|
|
45
|
+
const { htmlFor, id: idProp, ...labelProps } = props;
|
|
46
|
+
const controlRef = React.useRef(null);
|
|
47
|
+
const ref = React.useRef(null);
|
|
48
|
+
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
49
|
+
const id = useId(idProp);
|
|
50
|
+
if (isWeb) {
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
if (htmlFor) {
|
|
53
|
+
const element = document.getElementById(htmlFor);
|
|
54
|
+
const label = ref.current;
|
|
55
|
+
if (label && element) {
|
|
56
|
+
const getAriaLabel = () => element.getAttribute("aria-labelledby");
|
|
57
|
+
const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(" ");
|
|
58
|
+
element.setAttribute("aria-labelledby", ariaLabelledBy);
|
|
59
|
+
controlRef.current = element;
|
|
60
|
+
return () => {
|
|
61
|
+
var _a;
|
|
62
|
+
if (!id)
|
|
63
|
+
return;
|
|
64
|
+
const ariaLabelledBy2 = (_a = getAriaLabel()) == null ? void 0 : _a.replace(id, "");
|
|
65
|
+
if (ariaLabelledBy2 === "") {
|
|
66
|
+
element.removeAttribute("aria-labelledby");
|
|
67
|
+
} else if (ariaLabelledBy2) {
|
|
68
|
+
element.setAttribute("aria-labelledby", ariaLabelledBy2);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}, [id, htmlFor]);
|
|
74
|
+
}
|
|
75
|
+
return <LabelProvider id={id} controlRef={controlRef}><LabelFrame role="label" id={id} {...labelProps} ref={composedRefs} onMouseDown={(event) => {
|
|
76
|
+
var _a;
|
|
77
|
+
(_a = props.onMouseDown) == null ? void 0 : _a.call(props, event);
|
|
78
|
+
if (!event.defaultPrevented && event.detail > 1) {
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
}
|
|
81
|
+
}} onPress={(event) => {
|
|
82
|
+
var _a;
|
|
83
|
+
(_a = props.onPress) == null ? void 0 : _a.call(props, event);
|
|
84
|
+
if (isWeb) {
|
|
85
|
+
if (!controlRef.current || event.defaultPrevented)
|
|
86
|
+
return;
|
|
87
|
+
const isClickingControl = controlRef.current.contains(event.target);
|
|
88
|
+
const isUserClick = event.isTrusted === true;
|
|
89
|
+
if (!isClickingControl && isUserClick) {
|
|
90
|
+
controlRef.current.click();
|
|
91
|
+
controlRef.current.focus();
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
if (props.htmlFor) {
|
|
95
|
+
focusFocusable(props.htmlFor);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}} /></LabelProvider>;
|
|
99
|
+
});
|
|
100
|
+
LabelComponent.displayName = NAME;
|
|
101
|
+
const Label = LabelFrame.extractable(themeable(LabelComponent), {
|
|
102
|
+
neverFlatten: true
|
|
103
|
+
});
|
|
104
|
+
const useLabelContext = (element) => {
|
|
105
|
+
const context = useLabelContextImpl("LabelConsumer");
|
|
106
|
+
const { controlRef } = context;
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
if (element)
|
|
109
|
+
controlRef.current = element;
|
|
110
|
+
}, [element, controlRef]);
|
|
111
|
+
return context.id;
|
|
112
|
+
};
|
|
113
|
+
const Root = Label;
|
|
114
|
+
export {
|
|
115
|
+
Label,
|
|
116
|
+
LabelFrame,
|
|
117
|
+
useLabelContext
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=Label.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Label.tsx"],
|
|
4
|
+
"sourcesContent": ["import { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n ReactComponentWithRef,\n getButtonSize,\n getFont,\n isWeb,\n styled,\n themeable,\n useId,\n} from '@tamagui/core'\nimport { createContext } from '@tamagui/create-context'\nimport { focusFocusable } from '@tamagui/focusable'\nimport { SizableText } from '@tamagui/text'\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 size: '$4',\n backgroundColor: 'transparent',\n display: 'flex',\n alignItems: 'center',\n selectable: false,\n cursor: 'default',\n pressStyle: {\n color: '$colorPress',\n },\n variants: {\n size: {\n '...size': (val, extras) => {\n const buttonStyle = getButtonSize(val, extras)\n return {\n ...getFont(val, extras),\n height: buttonStyle.height,\n lineHeight: buttonStyle.height,\n }\n },\n },\n },\n})\n\nexport type LabelProps = GetProps<typeof LabelFrame> & {\n htmlFor?: string\n}\n\nconst LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>((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 id = useId(idProp)\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 // @ts-ignore\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) {\n event.preventDefault()\n }\n }}\n onPress={(event) => {\n props.onPress?.(event)\n\n if (isWeb) {\n if (!controlRef.current || event.defaultPrevented) return\n const isClickingControl = controlRef.current.contains(event.target as any 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 } else {\n if (props.htmlFor) {\n focusFocusable(props.htmlFor)\n }\n }\n }}\n />\n </LabelProvider>\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;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA;AACA;AACA;AACA;AAGA,MAAM,OAAO;AAOb,MAAM,CAAC,eAAe,uBAAuB,cAAiC,MAAM;AAAA,EAClF,IAAI;AAAA,EACJ,YAAY,EAAE,SAAS,KAAK;AAC9B,CAAC;AAEM,MAAM,aAAa,OAAO,aAAa;AAAA,EAC5C,MAAM;AAAA,EACN,KAAK;AAAA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ta.103",
|
|
4
|
+
"sideEffects": [
|
|
5
|
+
"*.css"
|
|
6
|
+
],
|
|
7
|
+
"source": "src/index.ts",
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
9
|
+
"main": "dist/cjs",
|
|
10
|
+
"module": "dist/esm",
|
|
11
|
+
"module:jsx": "dist/jsx",
|
|
12
|
+
"files": [
|
|
13
|
+
"src",
|
|
14
|
+
"types",
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tamagui-build",
|
|
19
|
+
"watch": "tamagui-build --watch",
|
|
20
|
+
"clean": "tamagui-build clean",
|
|
21
|
+
"clean:build": "tamagui-build clean:build"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@tamagui/compose-refs": "^1.0.1-beta.103",
|
|
25
|
+
"@tamagui/core": "^1.0.1-beta.103",
|
|
26
|
+
"@tamagui/create-context": "^1.0.1-beta.103",
|
|
27
|
+
"@tamagui/focusable": "^1.0.1-beta.103",
|
|
28
|
+
"@tamagui/text": "^1.0.1-beta.103"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": "*",
|
|
32
|
+
"react-dom": "*",
|
|
33
|
+
"react-native": "*"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@tamagui/build": "^1.0.1-beta.103",
|
|
37
|
+
"@types/react-native": "^0.69.2",
|
|
38
|
+
"react": "*",
|
|
39
|
+
"react-dom": "*",
|
|
40
|
+
"react-native": "*"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/Label.tsx
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { useComposedRefs } from '@tamagui/compose-refs'
|
|
2
|
+
import {
|
|
3
|
+
GetProps,
|
|
4
|
+
ReactComponentWithRef,
|
|
5
|
+
getButtonSize,
|
|
6
|
+
getFont,
|
|
7
|
+
isWeb,
|
|
8
|
+
styled,
|
|
9
|
+
themeable,
|
|
10
|
+
useId,
|
|
11
|
+
} from '@tamagui/core'
|
|
12
|
+
import { createContext } from '@tamagui/create-context'
|
|
13
|
+
import { focusFocusable } from '@tamagui/focusable'
|
|
14
|
+
import { SizableText } from '@tamagui/text'
|
|
15
|
+
import * as React from 'react'
|
|
16
|
+
import { View } from 'react-native'
|
|
17
|
+
|
|
18
|
+
const NAME = 'Label'
|
|
19
|
+
|
|
20
|
+
type LabelContextValue = {
|
|
21
|
+
id?: string
|
|
22
|
+
controlRef: React.MutableRefObject<HTMLElement | null>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const [LabelProvider, useLabelContextImpl] = createContext<LabelContextValue>(NAME, {
|
|
26
|
+
id: undefined,
|
|
27
|
+
controlRef: { current: null },
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
export const LabelFrame = styled(SizableText, {
|
|
31
|
+
name: 'Label',
|
|
32
|
+
tag: 'label',
|
|
33
|
+
size: '$4',
|
|
34
|
+
backgroundColor: 'transparent',
|
|
35
|
+
display: 'flex',
|
|
36
|
+
alignItems: 'center',
|
|
37
|
+
selectable: false,
|
|
38
|
+
cursor: 'default',
|
|
39
|
+
pressStyle: {
|
|
40
|
+
color: '$colorPress',
|
|
41
|
+
},
|
|
42
|
+
variants: {
|
|
43
|
+
size: {
|
|
44
|
+
'...size': (val, extras) => {
|
|
45
|
+
const buttonStyle = getButtonSize(val, extras)
|
|
46
|
+
return {
|
|
47
|
+
...getFont(val, extras),
|
|
48
|
+
height: buttonStyle.height,
|
|
49
|
+
lineHeight: buttonStyle.height,
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
export type LabelProps = GetProps<typeof LabelFrame> & {
|
|
57
|
+
htmlFor?: string
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const LabelComponent = React.forwardRef<typeof LabelFrame, LabelProps>((props, forwardedRef) => {
|
|
61
|
+
const { htmlFor, id: idProp, ...labelProps } = props
|
|
62
|
+
const controlRef = React.useRef<HTMLElement | null>(null)
|
|
63
|
+
const ref = React.useRef<any>(null)
|
|
64
|
+
const composedRefs = useComposedRefs(forwardedRef, ref)
|
|
65
|
+
const id = useId(idProp)
|
|
66
|
+
|
|
67
|
+
if (isWeb) {
|
|
68
|
+
React.useEffect(() => {
|
|
69
|
+
if (htmlFor) {
|
|
70
|
+
const element = document.getElementById(htmlFor)
|
|
71
|
+
const label = ref.current
|
|
72
|
+
if (label && element) {
|
|
73
|
+
const getAriaLabel = () => element.getAttribute('aria-labelledby')
|
|
74
|
+
const ariaLabelledBy = [id, getAriaLabel()].filter(Boolean).join(' ')
|
|
75
|
+
element.setAttribute('aria-labelledby', ariaLabelledBy)
|
|
76
|
+
controlRef.current = element
|
|
77
|
+
return () => {
|
|
78
|
+
/**
|
|
79
|
+
* We get the latest attribute value because at the time that this cleanup fires,
|
|
80
|
+
* the values from the closure may have changed.
|
|
81
|
+
*/
|
|
82
|
+
if (!id) return
|
|
83
|
+
const ariaLabelledBy = getAriaLabel()?.replace(id, '')
|
|
84
|
+
if (ariaLabelledBy === '') {
|
|
85
|
+
element.removeAttribute('aria-labelledby')
|
|
86
|
+
} else if (ariaLabelledBy) {
|
|
87
|
+
element.setAttribute('aria-labelledby', ariaLabelledBy)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}, [id, htmlFor])
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<LabelProvider id={id} controlRef={controlRef}>
|
|
97
|
+
<LabelFrame
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
role="label"
|
|
100
|
+
id={id}
|
|
101
|
+
{...labelProps}
|
|
102
|
+
ref={composedRefs}
|
|
103
|
+
onMouseDown={(event) => {
|
|
104
|
+
props.onMouseDown?.(event)
|
|
105
|
+
// prevent text selection when double clicking label
|
|
106
|
+
if (!event.defaultPrevented && event.detail > 1) {
|
|
107
|
+
event.preventDefault()
|
|
108
|
+
}
|
|
109
|
+
}}
|
|
110
|
+
onPress={(event) => {
|
|
111
|
+
props.onPress?.(event)
|
|
112
|
+
|
|
113
|
+
if (isWeb) {
|
|
114
|
+
if (!controlRef.current || event.defaultPrevented) return
|
|
115
|
+
const isClickingControl = controlRef.current.contains(event.target as any as Node)
|
|
116
|
+
// Ensure event was generated by a user action
|
|
117
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted
|
|
118
|
+
const isUserClick = event.isTrusted === true
|
|
119
|
+
/**
|
|
120
|
+
* When a label is wrapped around the control it labels, we trigger the appropriate events
|
|
121
|
+
* on the control when the label is clicked. We do nothing if the user is already clicking the
|
|
122
|
+
* control inside the label.
|
|
123
|
+
*/
|
|
124
|
+
if (!isClickingControl && isUserClick) {
|
|
125
|
+
controlRef.current.click()
|
|
126
|
+
controlRef.current.focus()
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
if (props.htmlFor) {
|
|
130
|
+
focusFocusable(props.htmlFor)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}}
|
|
134
|
+
/>
|
|
135
|
+
</LabelProvider>
|
|
136
|
+
)
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
LabelComponent.displayName = NAME
|
|
140
|
+
|
|
141
|
+
export const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View> =
|
|
142
|
+
LabelFrame.extractable(themeable(LabelComponent as any) as any, {
|
|
143
|
+
neverFlatten: true,
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
export const useLabelContext = (element?: HTMLElement | null) => {
|
|
147
|
+
const context = useLabelContextImpl('LabelConsumer')
|
|
148
|
+
const { controlRef } = context
|
|
149
|
+
|
|
150
|
+
React.useEffect(() => {
|
|
151
|
+
if (element) controlRef.current = element
|
|
152
|
+
}, [element, controlRef])
|
|
153
|
+
|
|
154
|
+
return context.id
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const Root = Label
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Label'
|
package/types/Label.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { GetProps, ReactComponentWithRef } from '@tamagui/core';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
export declare const LabelFrame: import("@tamagui/core").TamaguiComponent<Omit<import("react-native").TextProps, "children"> & import("@tamagui/core").RNWTextProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase>> & Omit<{
|
|
4
|
+
size?: import("@tamagui/core").FontSizeTokens | undefined;
|
|
5
|
+
}, "size"> & {
|
|
6
|
+
size?: import("@tamagui/core").SizeTokens | undefined;
|
|
7
|
+
} & import("@tamagui/core").MediaProps<Partial<Omit<import("react-native").TextProps, "children"> & import("@tamagui/core").RNWTextProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase>> & Omit<{
|
|
8
|
+
size?: import("@tamagui/core").FontSizeTokens | undefined;
|
|
9
|
+
}, "size"> & {
|
|
10
|
+
size?: import("@tamagui/core").SizeTokens | undefined;
|
|
11
|
+
}>> & import("@tamagui/core").PseudoProps<Partial<Omit<import("react-native").TextProps, "children"> & import("@tamagui/core").RNWTextProps & import("@tamagui/core").TamaguiComponentPropsBase & import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").TextStylePropsBase>> & Omit<{
|
|
12
|
+
size?: import("@tamagui/core").FontSizeTokens | undefined;
|
|
13
|
+
}, "size"> & {
|
|
14
|
+
size?: import("@tamagui/core").SizeTokens | undefined;
|
|
15
|
+
}>>, any, import("@tamagui/core").TextPropsBase, {
|
|
16
|
+
size?: import("@tamagui/core").FontSizeTokens | undefined;
|
|
17
|
+
} & {
|
|
18
|
+
size?: import("@tamagui/core").SizeTokens | undefined;
|
|
19
|
+
}>;
|
|
20
|
+
export declare type LabelProps = GetProps<typeof LabelFrame> & {
|
|
21
|
+
htmlFor?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare const Label: ReactComponentWithRef<LabelProps, HTMLButtonElement | View>;
|
|
24
|
+
export declare const useLabelContext: (element?: HTMLElement | null) => string | undefined;
|
|
25
|
+
//# sourceMappingURL=Label.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Label.d.ts","sourceRoot":"","sources":["../src/Label.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,qBAAqB,EAOtB,MAAM,eAAe,CAAA;AAKtB,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAcnC,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;EAwBrB,CAAA;AAEF,oBAAY,UAAU,GAAG,QAAQ,CAAC,OAAO,UAAU,CAAC,GAAG;IACrD,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAmFD,eAAO,MAAM,KAAK,EAAE,qBAAqB,CAAC,UAAU,EAAE,iBAAiB,GAAG,IAAI,CAG1E,CAAA;AAEJ,eAAO,MAAM,eAAe,aAAc,WAAW,GAAG,IAAI,uBAS3D,CAAA"}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
|