@tamagui/switch 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/Switch.js +262 -0
- package/dist/cjs/Switch.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/Switch.js +241 -0
- package/dist/esm/Switch.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/Switch.js +159 -0
- package/dist/jsx/Switch.js.map +7 -0
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/index.js.map +7 -0
- package/package.json +48 -0
- package/src/Switch.tsx +293 -0
- package/src/index.ts +1 -0
- package/types/Switch.d.ts +246 -0
- package/types/Switch.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,262 @@
|
|
|
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 Switch_exports = {};
|
|
51
|
+
__export(Switch_exports, {
|
|
52
|
+
Switch: () => Switch,
|
|
53
|
+
SwitchFrame: () => SwitchFrame,
|
|
54
|
+
SwitchThumb: () => SwitchThumb,
|
|
55
|
+
SwitchThumbFrame: () => SwitchThumbFrame,
|
|
56
|
+
createSwitchScope: () => createSwitchScope
|
|
57
|
+
});
|
|
58
|
+
module.exports = __toCommonJS(Switch_exports);
|
|
59
|
+
var import_react_use_previous = require("@radix-ui/react-use-previous");
|
|
60
|
+
var import_compose_refs = require("@tamagui/compose-refs");
|
|
61
|
+
var import_core = require("@tamagui/core");
|
|
62
|
+
var import_create_context = require("@tamagui/create-context");
|
|
63
|
+
var import_focusable = require("@tamagui/focusable");
|
|
64
|
+
var import_label = require("@tamagui/label");
|
|
65
|
+
var import_stacks = require("@tamagui/stacks");
|
|
66
|
+
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
67
|
+
var React = __toESM(require("react"));
|
|
68
|
+
const SWITCH_NAME = "Switch";
|
|
69
|
+
const getSwitchHeight = (val) => Math.round((0, import_core.getVariableValue)((0, import_core.getSize)(val)) * 0.65);
|
|
70
|
+
const getSwitchWidth = (val) => getSwitchHeight(val) * 2;
|
|
71
|
+
const scopeContexts = (0, import_create_context.createContextScope)(SWITCH_NAME);
|
|
72
|
+
const [createSwitchContext] = scopeContexts;
|
|
73
|
+
const createSwitchScope = scopeContexts[1];
|
|
74
|
+
const [SwitchProvider, useSwitchContext] = createSwitchContext(SWITCH_NAME);
|
|
75
|
+
const THUMB_NAME = "SwitchThumb";
|
|
76
|
+
const SwitchThumbFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
77
|
+
name: "SwitchThumb",
|
|
78
|
+
backgroundColor: "$background",
|
|
79
|
+
borderRadius: 1e3,
|
|
80
|
+
variants: {
|
|
81
|
+
size: {
|
|
82
|
+
"...size": (val) => ({
|
|
83
|
+
height: getSwitchHeight(val),
|
|
84
|
+
width: getSwitchHeight(val)
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
defaultVariants: {
|
|
89
|
+
size: "$4"
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const SwitchThumb = SwitchThumbFrame.extractable(React.forwardRef((props, forwardedRef) => {
|
|
93
|
+
const _a = props, { __scopeSwitch } = _a, thumbProps = __objRest(_a, ["__scopeSwitch"]);
|
|
94
|
+
const { size, disabled, checked } = useSwitchContext(THUMB_NAME, __scopeSwitch);
|
|
95
|
+
return /* @__PURE__ */ React.createElement(SwitchThumbFrame, __spreadProps(__spreadValues({
|
|
96
|
+
size,
|
|
97
|
+
"data-state": getState(checked),
|
|
98
|
+
"data-disabled": disabled ? "" : void 0
|
|
99
|
+
}, thumbProps), {
|
|
100
|
+
x: checked ? (0, import_core.getVariableValue)(getSwitchWidth(size)) - (0, import_core.getVariableValue)(getSwitchHeight(size)) : 0,
|
|
101
|
+
ref: forwardedRef
|
|
102
|
+
}));
|
|
103
|
+
}));
|
|
104
|
+
SwitchThumb.displayName = THUMB_NAME;
|
|
105
|
+
const SwitchFrame = (0, import_core.styled)(import_stacks.XStack, {
|
|
106
|
+
name: "Switch",
|
|
107
|
+
tag: "button",
|
|
108
|
+
borderRadius: 1e3,
|
|
109
|
+
borderWidth: 2,
|
|
110
|
+
borderColor: "transparent",
|
|
111
|
+
backgroundColor: "$background",
|
|
112
|
+
focusStyle: {
|
|
113
|
+
borderColor: "$borderColorFocus"
|
|
114
|
+
},
|
|
115
|
+
variants: {
|
|
116
|
+
size: {
|
|
117
|
+
"...size": (val) => {
|
|
118
|
+
const height = (0, import_core.calc)(getSwitchHeight(val), "+", 4);
|
|
119
|
+
const width = (0, import_core.calc)(getSwitchWidth(val), "+", 4);
|
|
120
|
+
return {
|
|
121
|
+
height,
|
|
122
|
+
minHeight: height,
|
|
123
|
+
width
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
defaultVariants: {
|
|
129
|
+
size: "$4"
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
const Switch = (0, import_core.withStaticProperties)(SwitchFrame.extractable(React.forwardRef((props, forwardedRef) => {
|
|
133
|
+
const _a = props, {
|
|
134
|
+
__scopeSwitch,
|
|
135
|
+
labeledBy: ariaLabelledby,
|
|
136
|
+
name,
|
|
137
|
+
checked: checkedProp,
|
|
138
|
+
defaultChecked,
|
|
139
|
+
required,
|
|
140
|
+
disabled,
|
|
141
|
+
value = "on",
|
|
142
|
+
onCheckedChange,
|
|
143
|
+
size = "$4"
|
|
144
|
+
} = _a, switchProps = __objRest(_a, [
|
|
145
|
+
"__scopeSwitch",
|
|
146
|
+
"labeledBy",
|
|
147
|
+
"name",
|
|
148
|
+
"checked",
|
|
149
|
+
"defaultChecked",
|
|
150
|
+
"required",
|
|
151
|
+
"disabled",
|
|
152
|
+
"value",
|
|
153
|
+
"onCheckedChange",
|
|
154
|
+
"size"
|
|
155
|
+
]);
|
|
156
|
+
const [button, setButton] = React.useState(null);
|
|
157
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, (node) => setButton(node));
|
|
158
|
+
const labelId = (0, import_label.useLabelContext)(button);
|
|
159
|
+
const labelledBy = ariaLabelledby || labelId;
|
|
160
|
+
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
161
|
+
const isFormControl = import_core.isWeb ? button ? Boolean(button.closest("form")) : true : false;
|
|
162
|
+
const [checked = false, setChecked] = (0, import_use_controllable_state.useControllableState)({
|
|
163
|
+
prop: checkedProp,
|
|
164
|
+
defaultProp: defaultChecked || false,
|
|
165
|
+
onChange: onCheckedChange
|
|
166
|
+
});
|
|
167
|
+
if (!import_core.isWeb) {
|
|
168
|
+
React.useEffect(() => {
|
|
169
|
+
if (!props.id)
|
|
170
|
+
return;
|
|
171
|
+
return (0, import_focusable.registerFocusable)(props.id, {
|
|
172
|
+
focus: () => {
|
|
173
|
+
setChecked((x) => !x);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}, [props.id, setChecked]);
|
|
177
|
+
}
|
|
178
|
+
return /* @__PURE__ */ React.createElement(SwitchProvider, {
|
|
179
|
+
scope: __scopeSwitch,
|
|
180
|
+
checked,
|
|
181
|
+
disabled,
|
|
182
|
+
size
|
|
183
|
+
}, /* @__PURE__ */ React.createElement(SwitchFrame, __spreadProps(__spreadValues({
|
|
184
|
+
size,
|
|
185
|
+
role: "switch",
|
|
186
|
+
"aria-checked": checked,
|
|
187
|
+
"aria-labelledby": labelledBy,
|
|
188
|
+
"aria-required": required,
|
|
189
|
+
"data-state": getState(checked),
|
|
190
|
+
"data-disabled": disabled ? "" : void 0,
|
|
191
|
+
disabled,
|
|
192
|
+
theme: checked ? "active" : null,
|
|
193
|
+
themeShallow: true,
|
|
194
|
+
tabIndex: disabled ? void 0 : 0,
|
|
195
|
+
value
|
|
196
|
+
}, switchProps), {
|
|
197
|
+
ref: composedRefs,
|
|
198
|
+
onPress: (event) => {
|
|
199
|
+
var _a2;
|
|
200
|
+
(_a2 = props.onPress) == null ? void 0 : _a2.call(props, event);
|
|
201
|
+
setChecked((prevChecked) => !prevChecked);
|
|
202
|
+
if (import_core.isWeb && isFormControl) {
|
|
203
|
+
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
204
|
+
if (!hasConsumerStoppedPropagationRef.current)
|
|
205
|
+
event.stopPropagation();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
})), import_core.isWeb && isFormControl && /* @__PURE__ */ React.createElement(BubbleInput, {
|
|
209
|
+
control: button,
|
|
210
|
+
bubbles: !hasConsumerStoppedPropagationRef.current,
|
|
211
|
+
name,
|
|
212
|
+
value,
|
|
213
|
+
checked,
|
|
214
|
+
required,
|
|
215
|
+
disabled,
|
|
216
|
+
style: { transform: "translateX(-100%)" }
|
|
217
|
+
}));
|
|
218
|
+
})), {
|
|
219
|
+
Thumb: SwitchThumb
|
|
220
|
+
});
|
|
221
|
+
const BubbleInput = (props) => {
|
|
222
|
+
const _a = props, { control, checked, bubbles = true } = _a, inputProps = __objRest(_a, ["control", "checked", "bubbles"]);
|
|
223
|
+
const ref = React.useRef(null);
|
|
224
|
+
const prevChecked = (0, import_react_use_previous.usePrevious)(checked);
|
|
225
|
+
React.useEffect(() => {
|
|
226
|
+
const input = ref.current;
|
|
227
|
+
const inputProto = window.HTMLInputElement.prototype;
|
|
228
|
+
const descriptor = Object.getOwnPropertyDescriptor(inputProto, "checked");
|
|
229
|
+
const setChecked = descriptor.set;
|
|
230
|
+
if (prevChecked !== checked && setChecked) {
|
|
231
|
+
const event = new Event("click", { bubbles });
|
|
232
|
+
setChecked.call(input, checked);
|
|
233
|
+
input.dispatchEvent(event);
|
|
234
|
+
}
|
|
235
|
+
}, [prevChecked, checked, bubbles]);
|
|
236
|
+
return /* @__PURE__ */ React.createElement("input", __spreadProps(__spreadValues({
|
|
237
|
+
type: "checkbox",
|
|
238
|
+
"aria-hidden": true,
|
|
239
|
+
defaultChecked: checked
|
|
240
|
+
}, inputProps), {
|
|
241
|
+
tabIndex: -1,
|
|
242
|
+
ref,
|
|
243
|
+
style: __spreadProps(__spreadValues({}, props.style), {
|
|
244
|
+
position: "absolute",
|
|
245
|
+
pointerEvents: "none",
|
|
246
|
+
opacity: 0,
|
|
247
|
+
margin: 0
|
|
248
|
+
})
|
|
249
|
+
}));
|
|
250
|
+
};
|
|
251
|
+
function getState(checked) {
|
|
252
|
+
return checked ? "checked" : "unchecked";
|
|
253
|
+
}
|
|
254
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
255
|
+
0 && (module.exports = {
|
|
256
|
+
Switch,
|
|
257
|
+
SwitchFrame,
|
|
258
|
+
SwitchThumb,
|
|
259
|
+
SwitchThumbFrame,
|
|
260
|
+
createSwitchScope
|
|
261
|
+
});
|
|
262
|
+
//# sourceMappingURL=Switch.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Switch.tsx"],
|
|
4
|
+
"sourcesContent": ["// via radix\n// https://github.com/radix-ui/primitives/blob/main/packages/react/switch/src/Switch.tsx\n\nimport { usePrevious } from '@radix-ui/react-use-previous'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n SizeTokens,\n Theme,\n calc,\n getSize,\n getVariableValue,\n isWeb,\n styled,\n themeable,\n useTheme,\n useThemeName,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ScopedProps, createContextScope } from '@tamagui/create-context'\nimport { registerFocusable } from '@tamagui/focusable'\nimport { useLabelContext } from '@tamagui/label'\nimport { ThemeableStack, XStack } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\nimport { View } from 'react-native'\n\nconst SWITCH_NAME = 'Switch'\n\n// TODO make customizable\nconst getSwitchHeight = (val: SizeTokens) => Math.round(getVariableValue(getSize(val)) * 0.65)\nconst getSwitchWidth = (val: SizeTokens) => getSwitchHeight(val) * 2\n\nconst scopeContexts = createContextScope(SWITCH_NAME)\nconst [createSwitchContext] = scopeContexts\nexport const createSwitchScope = scopeContexts[1]\n\nconst [SwitchProvider, useSwitchContext] = createSwitchContext<{\n checked: boolean\n disabled?: boolean\n size: SizeTokens\n}>(SWITCH_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * SwitchThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SwitchThumb'\n\nexport const SwitchThumbFrame = styled(ThemeableStack, {\n name: 'SwitchThumb',\n backgroundColor: '$background',\n borderRadius: 1000,\n\n variants: {\n size: {\n '...size': (val) => ({\n height: getSwitchHeight(val),\n width: getSwitchHeight(val),\n }),\n },\n },\n\n defaultVariants: {\n size: '$4',\n },\n})\n\nexport type SwitchThumbProps = GetProps<typeof SwitchThumbFrame>\n\nexport const SwitchThumb = SwitchThumbFrame.extractable(\n React.forwardRef<React.ElementRef<'span'>, SwitchThumbProps>(\n (props: ScopedProps<SwitchThumbProps, 'Switch'>, forwardedRef) => {\n const { __scopeSwitch, ...thumbProps } = props\n const { size, disabled, checked } = useSwitchContext(THUMB_NAME, __scopeSwitch)\n return (\n <SwitchThumbFrame\n size={size}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n {...thumbProps}\n x={\n checked\n ? getVariableValue(getSwitchWidth(size)) - getVariableValue(getSwitchHeight(size))\n : 0\n }\n ref={forwardedRef}\n />\n )\n }\n )\n)\n\nSwitchThumb.displayName = THUMB_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Switch\n * -----------------------------------------------------------------------------------------------*/\n\nexport const SwitchFrame = styled(XStack, {\n name: 'Switch',\n tag: 'button',\n borderRadius: 1000,\n borderWidth: 2,\n borderColor: 'transparent',\n backgroundColor: '$background',\n\n focusStyle: {\n borderColor: '$borderColorFocus',\n },\n\n variants: {\n size: {\n '...size': (val) => {\n const height = calc(getSwitchHeight(val), '+', 4)\n const width = calc(getSwitchWidth(val), '+', 4)\n return {\n height,\n minHeight: height,\n width,\n }\n },\n },\n },\n\n defaultVariants: {\n size: '$4',\n },\n})\n\ntype SwitchButtonProps = GetProps<typeof SwitchFrame>\n\nexport type SwitchProps = SwitchButtonProps & {\n labeledBy?: string\n name?: string\n value?: string\n checked?: boolean\n defaultChecked?: boolean\n required?: boolean\n onCheckedChange?(checked: boolean): void\n}\n\nexport const Switch = withStaticProperties(\n SwitchFrame.extractable(\n React.forwardRef<HTMLButtonElement | View, SwitchProps>(\n (props: ScopedProps<SwitchProps, 'Switch'>, forwardedRef) => {\n const {\n __scopeSwitch,\n labeledBy: ariaLabelledby,\n name,\n checked: checkedProp,\n defaultChecked,\n required,\n disabled,\n value = 'on',\n onCheckedChange,\n size = '$4',\n ...switchProps\n } = props\n const [button, setButton] = React.useState<HTMLButtonElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node as any))\n const labelId = useLabelContext(button)\n const labelledBy = ariaLabelledby || labelId\n const hasConsumerStoppedPropagationRef = React.useRef(false)\n // We set this to true by default so that events bubble to forms without JS (SSR)\n const isFormControl = isWeb ? (button ? Boolean(button.closest('form')) : true) : false\n const [checked = false, setChecked] = useControllableState({\n prop: checkedProp,\n defaultProp: defaultChecked || false,\n onChange: onCheckedChange,\n })\n\n if (!isWeb) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (!props.id) return\n return registerFocusable(props.id, {\n focus: () => {\n setChecked((x) => !x)\n },\n })\n }, [props.id, setChecked])\n }\n\n return (\n <SwitchProvider scope={__scopeSwitch} checked={checked} disabled={disabled} size={size}>\n <SwitchFrame\n size={size}\n // @ts-ignore\n role=\"switch\"\n aria-checked={checked}\n aria-labelledby={labelledBy}\n aria-required={required}\n data-state={getState(checked)}\n data-disabled={disabled ? '' : undefined}\n disabled={disabled}\n theme={checked ? 'active' : null}\n themeShallow\n // @ts-ignore\n tabIndex={disabled ? undefined : 0}\n // @ts-ignore\n value={value}\n {...switchProps}\n ref={composedRefs}\n onPress={(event) => {\n props.onPress?.(event)\n setChecked((prevChecked) => !prevChecked)\n if (isWeb && isFormControl) {\n hasConsumerStoppedPropagationRef.current = event.isPropagationStopped()\n // if switch is in a form, stop propagation from the button so that we only propagate\n // one click event (from the input). We propagate changes from an input so that native\n // form validation works and form events reflect switch updates.\n if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation()\n }\n }}\n />\n {isWeb && isFormControl && (\n <BubbleInput\n control={button}\n bubbles={!hasConsumerStoppedPropagationRef.current}\n name={name}\n value={value}\n checked={checked}\n required={required}\n disabled={disabled}\n // We transform because the input is absolutely positioned but we have\n // rendered it **after** the button. This pulls it back to sit on top\n // of the button.\n style={{ transform: 'translateX(-100%)' }}\n />\n )}\n </SwitchProvider>\n )\n }\n )\n ),\n {\n Thumb: SwitchThumb,\n }\n)\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype InputProps = any //Radix.ComponentPropsWithoutRef<'input'>\ninterface BubbleInputProps extends Omit<InputProps, 'checked'> {\n checked: boolean\n control: HTMLElement | null\n bubbles: boolean\n}\n\n// TODO make this native friendly\nconst BubbleInput = (props: BubbleInputProps) => {\n const { control, checked, bubbles = true, ...inputProps } = props\n const ref = React.useRef<HTMLInputElement>(null)\n const prevChecked = usePrevious(checked)\n // const controlSize = useSize(control)\n\n // Bubble checked change to parents (e.g form change event)\n React.useEffect(() => {\n const input = ref.current!\n const inputProto = window.HTMLInputElement.prototype\n const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'checked') as PropertyDescriptor\n const setChecked = descriptor.set\n if (prevChecked !== checked && setChecked) {\n const event = new Event('click', { bubbles })\n setChecked.call(input, checked)\n input.dispatchEvent(event)\n }\n }, [prevChecked, checked, bubbles])\n\n return (\n <input\n type=\"checkbox\"\n aria-hidden\n defaultChecked={checked}\n {...inputProps}\n tabIndex={-1}\n ref={ref}\n style={{\n ...props.style,\n // ...controlSize,\n position: 'absolute',\n pointerEvents: 'none',\n opacity: 0,\n margin: 0,\n }}\n />\n )\n}\n\nfunction getState(checked: boolean) {\n return checked ? 'checked' : 'unchecked'\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,gCAA4B;AAC5B,0BAAgC;AAChC,kBAaO;AACP,4BAAgD;AAChD,uBAAkC;AAClC,mBAAgC;AAChC,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AI;AAC/C,QAAM,cAAc,2CAAY,OAAO;AAIvC,QAAM,UAAU,MAAM;AACpB,UAAM,QAAQ,IAAI;AAClB,UAAM,aAAa,OAAO,iBAAiB;AAC3C,UAAM,aAAa,OAAO,yBAAyB,YAAY,SAAS;AACxE,UAAM,aAAa,WAAW;AAC9B,QAAI,gBAAgB,WAAW,YAAY;AACzC,YAAM,QAAQ,IAAI,MAAM,SAAS,EAAE,QAAQ,CAAC;AAC5C,iBAAW,KAAK,OAAO,OAAO;AAC9B,YAAM,cAAc,KAAK;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,aAAa,SAAS,OAAO,CAAC;AAElC,SACE,oCAAC;AAAA,IACC,MAAK;AAAA,IACL,eAAW;AAAA,IACX,gBAAgB;AAAA,KACZ,aAJL;AAAA,IAKC,UAAU;AAAA,IACV;AAAA,IACA,OAAO,iCACF,MAAM,QADJ;AAAA,MAGL,UAAU;AAAA,MACV,eAAe;AAAA,MACf,SAAS;AAAA,MACT,QAAQ;AAAA,IACV;AAAA,IACF;AAEJ;AAEA,kBAAkB,SAAkB;AAClC,SAAO,UAAU,YAAY;AAC/B;",
|
|
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("./Switch"), 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: CardHe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