@yahoo/uds 0.2.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/cli/README.md +78 -131
- package/cli/commands/purge.ts +7 -3
- package/cli/env.d.ts +1 -0
- package/cli/preload.ts +10 -0
- package/cli/utils/purgeCSS.test.ts +88 -8
- package/cli/utils/purgeCSS.ts +165 -15
- package/dist/Image.native-B3I4JoH3.d.cts +38 -0
- package/dist/Image.native-DUAFJodS.d.ts +38 -0
- package/dist/VStack-BHlRUsOR.d.cts +103 -0
- package/dist/VStack-DMb_RGRS.d.ts +103 -0
- package/dist/experimental/index.cjs +1 -1
- package/dist/experimental/index.d.cts +8 -8
- package/dist/experimental/index.d.ts +8 -8
- package/dist/experimental/index.js +1 -1
- package/dist/experimental/index.native.cjs +1 -1
- package/dist/experimental/index.native.d.cts +3 -3
- package/dist/experimental/index.native.d.ts +3 -3
- package/dist/experimental/index.native.js +1 -1
- package/dist/fixtures.cjs +1946 -0
- package/dist/fixtures.d.ts +81 -0
- package/dist/fixtures.js +1910 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +41 -236
- package/dist/index.d.ts +41 -236
- package/dist/index.js +1 -1
- package/dist/{index.native-CisPq4BI.d.ts → index.native-BTfOSmUx.d.ts} +1 -1
- package/dist/{index.native-DJlx-bfM.d.cts → index.native-Bm-r2Dpa.d.cts} +1 -1
- package/dist/index.native.cjs +1 -1
- package/dist/index.native.d.cts +20 -83
- package/dist/index.native.d.ts +20 -83
- package/dist/index.native.js +1 -1
- package/dist/styles/globals.css +0 -1
- package/dist/styles/toast.css +1 -0
- package/dist/styles/toast.d.cts +2 -0
- package/dist/styles/toast.d.ts +2 -0
- package/dist/tailwindPlugin.cjs +1 -1
- package/dist/tailwindPlugin.d.cts +8 -2
- package/dist/tailwindPlugin.d.ts +8 -2
- package/dist/tailwindPlugin.js +1 -1
- package/dist/tailwindPurge/utils.cjs +1 -0
- package/dist/tailwindPurge/utils.d.cts +25 -0
- package/dist/tailwindPurge/utils.d.ts +25 -0
- package/dist/tailwindPurge/utils.js +1 -0
- package/dist/tailwindPurge.cjs +1 -1
- package/dist/tailwindPurge.d.cts +5 -1
- package/dist/tailwindPurge.d.ts +5 -1
- package/dist/tailwindPurge.js +1 -1
- package/dist/tokens/index.cjs +1 -1
- package/dist/tokens/index.d.cts +2 -2
- package/dist/tokens/index.d.ts +2 -2
- package/dist/tokens/index.js +1 -1
- package/dist/tokens/index.native.cjs +1 -1
- package/dist/tokens/index.native.d.cts +2 -2
- package/dist/tokens/index.native.d.ts +2 -2
- package/dist/tokens/index.native.js +1 -1
- package/dist/tokens/parseTokens.cjs +1 -1
- package/dist/tokens/parseTokens.d.cts +8 -18
- package/dist/tokens/parseTokens.d.ts +8 -18
- package/dist/tokens/parseTokens.js +1 -1
- package/dist/tokens/parseTokens.native.cjs +1 -1
- package/dist/tokens/parseTokens.native.d.cts +4 -21
- package/dist/tokens/parseTokens.native.d.ts +4 -21
- package/dist/tokens/parseTokens.native.js +1 -1
- package/dist/{types-CzJpH_Oi.d.cts → types-COiuE8XK.d.cts} +49 -138
- package/dist/{types-CzJpH_Oi.d.ts → types-COiuE8XK.d.ts} +49 -138
- package/package.json +26 -11
- package/dist/Image.native-C6kOWgnf.d.ts +0 -38
- package/dist/Image.native-VeXt5aeI.d.cts +0 -38
- package/dist/VStack-BSD9TbBd.d.cts +0 -114
- package/dist/VStack-Dk3-8IyU.d.ts +0 -114
- package/dist/fixtures/index.cjs +0 -1
- package/dist/fixtures/index.d.cts +0 -154
- package/dist/fixtures/index.d.ts +0 -154
- package/dist/fixtures/index.js +0 -1
package/cli/utils/purgeCSS.ts
CHANGED
@@ -2,20 +2,54 @@ import path from 'node:path';
|
|
2
2
|
|
3
3
|
import {
|
4
4
|
componentsDependencies,
|
5
|
+
componentToTwClasses,
|
5
6
|
componentToVariants,
|
6
7
|
variantsList,
|
7
8
|
variantToTailwindClass,
|
8
9
|
} from '@yahoo/uds/tailwindPurge';
|
9
|
-
import {
|
10
|
+
import {
|
11
|
+
findReferencesAsJsxElements,
|
12
|
+
getUsedPropsInReference,
|
13
|
+
} from '@yahoo/uds/tailwindPurge/utils';
|
14
|
+
import {
|
15
|
+
ColorModeConfig,
|
16
|
+
DARK_COLOR_MODE_CLASSNAME,
|
17
|
+
LARGE_SCALE_MODE_CLASSNAME,
|
18
|
+
LIGHT_COLOR_MODE_CLASSNAME,
|
19
|
+
MEDIUM_SCALE_MODE_CLASSNAME,
|
20
|
+
ScaleModeConfig,
|
21
|
+
SMALL_SCALE_MODE_CLASSNAME,
|
22
|
+
UniversalTokensConfig,
|
23
|
+
XLARGE_SCALE_MODE_CLASSNAME,
|
24
|
+
XSMALL_SCALE_MODE_CLASSNAME,
|
25
|
+
XXLARGE_SCALE_MODE_CLASSNAME,
|
26
|
+
XXXLARGE_SCALE_MODE_CLASSNAME,
|
27
|
+
} from '@yahoo/uds/tokens';
|
28
|
+
import { print, spinStart, spinStop } from 'bluebun';
|
10
29
|
import FastGlob from 'fast-glob';
|
11
|
-
import { Project } from 'ts-morph';
|
30
|
+
import { JsxOpeningElement, JsxSelfClosingElement, Project, ts } from 'ts-morph';
|
31
|
+
|
32
|
+
const scaleModeToClass: { [key in keyof ScaleModeConfig]: string } = {
|
33
|
+
large: LARGE_SCALE_MODE_CLASSNAME,
|
34
|
+
medium: MEDIUM_SCALE_MODE_CLASSNAME,
|
35
|
+
small: SMALL_SCALE_MODE_CLASSNAME,
|
36
|
+
xLarge: XLARGE_SCALE_MODE_CLASSNAME,
|
37
|
+
xSmall: XSMALL_SCALE_MODE_CLASSNAME,
|
38
|
+
xxLarge: XXLARGE_SCALE_MODE_CLASSNAME,
|
39
|
+
xxxLarge: XXXLARGE_SCALE_MODE_CLASSNAME,
|
40
|
+
};
|
41
|
+
|
42
|
+
const colorModeToClass: { [key in keyof ColorModeConfig]: string } = {
|
43
|
+
dark: DARK_COLOR_MODE_CLASSNAME,
|
44
|
+
light: LIGHT_COLOR_MODE_CLASSNAME,
|
45
|
+
};
|
12
46
|
|
13
|
-
type SafeList = string;
|
47
|
+
type SafeList = string[];
|
14
48
|
type ImportsList = string[];
|
15
49
|
type Files = string[];
|
16
50
|
|
17
51
|
// TODO: use CLI args to power the output file path
|
18
|
-
const OUTPUT_FILE_PATH = Bun.file(`${Bun.env.PWD}/dist/safelist.
|
52
|
+
const OUTPUT_FILE_PATH = Bun.file(`${Bun.env.PWD}/dist/safelist.ts`);
|
19
53
|
|
20
54
|
export const getFiles = async (): Promise<Files> => {
|
21
55
|
const workspaceDir = Bun.env.PWD;
|
@@ -25,6 +59,37 @@ export const getFiles = async (): Promise<Files> => {
|
|
25
59
|
return files;
|
26
60
|
};
|
27
61
|
|
62
|
+
/**
|
63
|
+
* Find all JSX references for a named import.
|
64
|
+
*
|
65
|
+
* @example
|
66
|
+
* const references = findNamedImportReferences(project, '@yahoo/uds', 'HStack')
|
67
|
+
*/
|
68
|
+
export function findNamedImportReferences(
|
69
|
+
project: Project,
|
70
|
+
moduleSpecifierValue: string,
|
71
|
+
namedImportName: string,
|
72
|
+
) {
|
73
|
+
const references: (JsxOpeningElement | JsxSelfClosingElement)[] = [];
|
74
|
+
for (const sourceFile of project.getSourceFiles()) {
|
75
|
+
for (const importDeclaration of sourceFile.getImportDeclarations()) {
|
76
|
+
if (importDeclaration.getModuleSpecifierValue() === moduleSpecifierValue) {
|
77
|
+
for (const namedImport of importDeclaration.getNamedImports()) {
|
78
|
+
if (namedImport.getName() === namedImportName) {
|
79
|
+
const identifier = namedImport.getFirstDescendantByKindOrThrow(
|
80
|
+
ts.SyntaxKind.Identifier,
|
81
|
+
);
|
82
|
+
|
83
|
+
references.push(...findReferencesAsJsxElements(identifier));
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
return references;
|
91
|
+
}
|
92
|
+
|
28
93
|
/**
|
29
94
|
* Given a file it returns the list of imports from @yahoo/uds
|
30
95
|
*/
|
@@ -39,7 +104,10 @@ export const parseFiles = (project: Project, files: Files): ImportsList => {
|
|
39
104
|
sourceFile
|
40
105
|
?.getImportDeclarations()
|
41
106
|
.filter((declaration) => {
|
42
|
-
return
|
107
|
+
return (
|
108
|
+
declaration.getModuleSpecifier().getText().includes('@yahoo/uds') ||
|
109
|
+
declaration.getModuleSpecifier().getText().includes('@yahoo/uds/experimental')
|
110
|
+
);
|
43
111
|
})
|
44
112
|
.map((declaration) => {
|
45
113
|
return declaration.getNamedImports().map((namedImport) => namedImport.getName());
|
@@ -59,26 +127,58 @@ export const parseFiles = (project: Project, files: Files): ImportsList => {
|
|
59
127
|
return Array.from(importsSet) as string[];
|
60
128
|
};
|
61
129
|
|
62
|
-
export const getTailwindSafelist = (componentList: string[]): SafeList => {
|
130
|
+
export const getTailwindSafelist = (project: Project, componentList: string[]): SafeList => {
|
131
|
+
const safeList: SafeList = [];
|
63
132
|
const validVariants = new Set<string>(variantsList);
|
64
133
|
const usedProps = new Set<string>();
|
65
134
|
componentList.forEach((component: string) => {
|
66
135
|
if (isUDSComponent(component)) {
|
136
|
+
// get the TW classes relevant for each prop
|
137
|
+
// these classes are used internally in UDS,
|
138
|
+
// they either have been initialized or used by other UDS components
|
67
139
|
componentToVariants[component].forEach((prop: string) => {
|
68
140
|
if (validVariants.has(prop) && !usedProps.has(prop)) {
|
69
141
|
usedProps.add(prop);
|
70
142
|
}
|
71
143
|
});
|
144
|
+
|
145
|
+
// scan the project for used props and
|
146
|
+
// get the corresponding css for those used props
|
147
|
+
getUsedProps(project, component).forEach((prop: string) => {
|
148
|
+
if (validVariants.has(prop) && !usedProps.has(prop)) {
|
149
|
+
usedProps.add(prop);
|
150
|
+
}
|
151
|
+
});
|
152
|
+
|
153
|
+
// get the inline TW classes used in each component
|
154
|
+
safeList.push(...componentToTwClasses[component].replaceAll('\\', '').split(' '));
|
72
155
|
}
|
73
156
|
});
|
74
157
|
|
75
|
-
let safeList = '';
|
76
158
|
for (const prop of usedProps) {
|
77
|
-
safeList
|
159
|
+
safeList.push(...variantToTailwindClass[prop].replaceAll('\\', '').split(' '));
|
78
160
|
}
|
161
|
+
|
79
162
|
return safeList;
|
80
163
|
};
|
81
164
|
|
165
|
+
/**
|
166
|
+
* Get the used props for a given component.
|
167
|
+
*
|
168
|
+
* @example
|
169
|
+
* const usedProps = getUsedProps(project, 'HStack');
|
170
|
+
*/
|
171
|
+
export const getUsedProps = (project: Project, component: string) => {
|
172
|
+
const references: (JsxOpeningElement | JsxSelfClosingElement)[] = [];
|
173
|
+
references.push(...findNamedImportReferences(project, '@yahoo/uds', component));
|
174
|
+
references.push(...findNamedImportReferences(project, '@yahoo/uds/experimental', component));
|
175
|
+
|
176
|
+
// for each reference find the used/references props
|
177
|
+
const usedProps = references.map((reference) => getUsedPropsInReference(reference)).flat();
|
178
|
+
|
179
|
+
return usedProps;
|
180
|
+
};
|
181
|
+
|
82
182
|
export const isUDSComponent = (component: string): boolean => {
|
83
183
|
return !!componentToVariants[component];
|
84
184
|
};
|
@@ -88,7 +188,7 @@ const saveToFile = async (safeList: SafeList) => {
|
|
88
188
|
//! This file is generated by purgeCSS.ts from @yahoo/uds
|
89
189
|
//! Do not edit directly
|
90
190
|
//! If there is issue with this file please report to #ask-uds
|
91
|
-
const
|
191
|
+
export const safelist = ${JSON.stringify(safeList)};
|
92
192
|
`;
|
93
193
|
|
94
194
|
await Bun.write(OUTPUT_FILE_PATH, fileContent);
|
@@ -113,24 +213,74 @@ export const getComponentsToConvertToTW = (udsImport: ImportsList): string[] =>
|
|
113
213
|
return Array.from(set) as string[];
|
114
214
|
};
|
115
215
|
|
116
|
-
|
216
|
+
/**
|
217
|
+
* Get the classes that corresponds to the used modes
|
218
|
+
*/
|
219
|
+
export const getClassesForEnabledThemesAndScales = (config: UniversalTokensConfig): string[] => {
|
220
|
+
const classes: string[] = [];
|
221
|
+
|
222
|
+
// TODO: Remove this once the config supports toggling colorModes and scaleModes
|
223
|
+
if (Bun.env.ENABLED_SCALE_AND_COLOR_MODES) {
|
224
|
+
Bun.env.ENABLED_SCALE_AND_COLOR_MODES.split(',').map((mode) => {
|
225
|
+
mode = mode.trim();
|
226
|
+
if (colorModeToClass[mode as keyof ColorModeConfig]) {
|
227
|
+
classes.push(colorModeToClass[mode as keyof ColorModeConfig]);
|
228
|
+
} else if (scaleModeToClass[mode as keyof ScaleModeConfig]) {
|
229
|
+
classes.push(scaleModeToClass[mode as keyof ScaleModeConfig]);
|
230
|
+
}
|
231
|
+
});
|
232
|
+
} else {
|
233
|
+
for (const colorMode in config.colorMode) {
|
234
|
+
classes.push(colorModeToClass[colorMode as keyof ColorModeConfig]);
|
235
|
+
}
|
236
|
+
for (const scaleMode in config.scaleMode) {
|
237
|
+
classes.push(scaleModeToClass[scaleMode as keyof ScaleModeConfig]);
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
return classes;
|
242
|
+
};
|
243
|
+
|
244
|
+
type PurgeOptions = {
|
245
|
+
config?: string;
|
246
|
+
};
|
247
|
+
|
248
|
+
async function purge({
|
249
|
+
config: configPath = Bun.env.UDS_OUT_FILE ?? './uds.config.ts',
|
250
|
+
}: PurgeOptions) {
|
117
251
|
const workspaceDir = Bun.env.PWD;
|
118
252
|
const srcDir = path.join(workspaceDir, '/tsconfig.json');
|
119
253
|
const project = new Project({
|
120
254
|
tsConfigFilePath: srcDir,
|
121
255
|
});
|
122
256
|
|
257
|
+
// we need to load the UDS config
|
258
|
+
const configAbsolutePath = path.resolve(workspaceDir, configPath);
|
259
|
+
const { config } = await import(configAbsolutePath);
|
260
|
+
|
123
261
|
spinStart('Getting used UDS components...');
|
124
|
-
|
262
|
+
|
263
|
+
// 1. Get all files from the current dir
|
264
|
+
print('Loading the project...');
|
125
265
|
const files = await getFiles();
|
266
|
+
|
126
267
|
// 2. For each file get the imports;
|
268
|
+
print('Going through the imports...');
|
127
269
|
const udsImports = parseFiles(project, files);
|
128
|
-
|
270
|
+
|
271
|
+
// 3. Now that we have the imported components
|
272
|
+
print('Finding all the components imported from UDS...');
|
129
273
|
const udsComponents = getComponentsToConvertToTW(udsImports);
|
274
|
+
|
130
275
|
// 4. Generate the CSS we need
|
131
|
-
|
276
|
+
print('🧑🍳 Cooking...');
|
277
|
+
const safeList = getTailwindSafelist(project, udsComponents);
|
278
|
+
const themesAndScalesClasses = getClassesForEnabledThemesAndScales(config);
|
279
|
+
|
132
280
|
// 5. Write the allowlist to a file
|
133
|
-
await saveToFile(safeList);
|
281
|
+
await saveToFile(safeList.concat(themesAndScalesClasses));
|
282
|
+
|
283
|
+
spinStop('Generated your safelist!');
|
134
284
|
}
|
135
285
|
|
136
|
-
export { purge };
|
286
|
+
export { purge, type PurgeOptions };
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import * as react from 'react';
|
2
|
+
import { i as UniversalPressableProps, j as UniversalIconButtonProps, k as UniversalImageProps } from './types-COiuE8XK.cjs';
|
3
|
+
import { View, PressableProps as PressableProps$1, StyleProp, ViewStyle } from 'react-native';
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
5
|
+
import { ImageProps as ImageProps$1 } from 'expo-image';
|
6
|
+
|
7
|
+
type NativePressableProps = Omit<PressableProps$1, 'children' | 'style' | 'onPress'> & {
|
8
|
+
style?: StyleProp<ViewStyle>;
|
9
|
+
};
|
10
|
+
interface PressableProps extends UniversalPressableProps, NativePressableProps {
|
11
|
+
}
|
12
|
+
declare const Pressable: react.ForwardRefExoticComponent<PressableProps & react.RefAttributes<View>>;
|
13
|
+
|
14
|
+
interface IconButtonProps extends PressableProps, UniversalIconButtonProps {
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* An icon button element that can be used to trigger an action.
|
18
|
+
* @example
|
19
|
+
```tsx
|
20
|
+
import { IconButton } from "@yahoo/uds";
|
21
|
+
|
22
|
+
export function IconButtonDemo() {
|
23
|
+
return (
|
24
|
+
<IconButton variant="accent-outline" color="primary" name="close" onPress={console.log} />
|
25
|
+
)
|
26
|
+
}
|
27
|
+
```
|
28
|
+
*/
|
29
|
+
declare const IconButton: react.ForwardRefExoticComponent<IconButtonProps & react.RefAttributes<View>>;
|
30
|
+
|
31
|
+
interface ImageProps extends Omit<ImageProps$1, 'alt' | 'source'>, UniversalImageProps {
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* An image element
|
35
|
+
*/
|
36
|
+
declare function Image({ width: imageWidth, height: imageHeight, src, alt, contentFit, backgroundColor, borderRadius, borderTopStartRadius, borderTopEndRadius, borderBottomStartRadius, borderBottomEndRadius, borderColor, borderColorOnActive, borderColorOnFocus, borderColorOnChecked, borderColorOnHover, borderStartColor, borderEndColor, borderTopColor, borderBottomColor, borderWidth, borderVerticalWidth, borderHorizontalWidth, borderStartWidth, borderEndWidth, borderTopWidth, borderBottomWidth, alignContent, alignItems, alignSelf, flex, flexDirection, flexGrow, flexShrink, flexWrap, justifyContent, flexBasis, display, overflow, overflowX, overflowY, position, spacing, spacingHorizontal, spacingVertical, spacingBottom, spacingEnd, spacingStart, spacingTop, offset, offsetVertical, offsetHorizontal, offsetBottom, offsetEnd, offsetStart, offsetTop, columnGap, rowGap, minHeight, maxHeight, minWidth, maxWidth, ...props }: ImageProps): react_jsx_runtime.JSX.Element;
|
37
|
+
|
38
|
+
export { type ImageProps as I, type PressableProps as P, IconButton as a, type IconButtonProps as b, Image as c, Pressable as d };
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import * as react from 'react';
|
2
|
+
import { i as UniversalPressableProps, j as UniversalIconButtonProps, k as UniversalImageProps } from './types-COiuE8XK.js';
|
3
|
+
import { View, PressableProps as PressableProps$1, StyleProp, ViewStyle } from 'react-native';
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
5
|
+
import { ImageProps as ImageProps$1 } from 'expo-image';
|
6
|
+
|
7
|
+
type NativePressableProps = Omit<PressableProps$1, 'children' | 'style' | 'onPress'> & {
|
8
|
+
style?: StyleProp<ViewStyle>;
|
9
|
+
};
|
10
|
+
interface PressableProps extends UniversalPressableProps, NativePressableProps {
|
11
|
+
}
|
12
|
+
declare const Pressable: react.ForwardRefExoticComponent<PressableProps & react.RefAttributes<View>>;
|
13
|
+
|
14
|
+
interface IconButtonProps extends PressableProps, UniversalIconButtonProps {
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* An icon button element that can be used to trigger an action.
|
18
|
+
* @example
|
19
|
+
```tsx
|
20
|
+
import { IconButton } from "@yahoo/uds";
|
21
|
+
|
22
|
+
export function IconButtonDemo() {
|
23
|
+
return (
|
24
|
+
<IconButton variant="accent-outline" color="primary" name="close" onPress={console.log} />
|
25
|
+
)
|
26
|
+
}
|
27
|
+
```
|
28
|
+
*/
|
29
|
+
declare const IconButton: react.ForwardRefExoticComponent<IconButtonProps & react.RefAttributes<View>>;
|
30
|
+
|
31
|
+
interface ImageProps extends Omit<ImageProps$1, 'alt' | 'source'>, UniversalImageProps {
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* An image element
|
35
|
+
*/
|
36
|
+
declare function Image({ width: imageWidth, height: imageHeight, src, alt, contentFit, backgroundColor, borderRadius, borderTopStartRadius, borderTopEndRadius, borderBottomStartRadius, borderBottomEndRadius, borderColor, borderColorOnActive, borderColorOnFocus, borderColorOnChecked, borderColorOnHover, borderStartColor, borderEndColor, borderTopColor, borderBottomColor, borderWidth, borderVerticalWidth, borderHorizontalWidth, borderStartWidth, borderEndWidth, borderTopWidth, borderBottomWidth, alignContent, alignItems, alignSelf, flex, flexDirection, flexGrow, flexShrink, flexWrap, justifyContent, flexBasis, display, overflow, overflowX, overflowY, position, spacing, spacingHorizontal, spacingVertical, spacingBottom, spacingEnd, spacingStart, spacingTop, offset, offsetVertical, offsetHorizontal, offsetBottom, offsetEnd, offsetStart, offsetTop, columnGap, rowGap, minHeight, maxHeight, minWidth, maxWidth, ...props }: ImageProps): react_jsx_runtime.JSX.Element;
|
37
|
+
|
38
|
+
export { type ImageProps as I, type PressableProps as P, IconButton as a, type IconButtonProps as b, Image as c, Pressable as d };
|
@@ -0,0 +1,103 @@
|
|
1
|
+
import * as react from 'react';
|
2
|
+
import { Ref } from 'react';
|
3
|
+
import { aS as UniversalBoxProps, i as UniversalPressableProps, aU as UniversalTextProps, l as UniversalStackProps } from './types-COiuE8XK.cjs';
|
4
|
+
|
5
|
+
type DivProps = React.HTMLAttributes<HTMLDivElement>;
|
6
|
+
interface BoxProps extends UniversalBoxProps, DivProps {
|
7
|
+
}
|
8
|
+
/**
|
9
|
+
* A layout primitive that can be used to compose other components. By default,
|
10
|
+
* `Box` is a flexbox container.
|
11
|
+
*
|
12
|
+
* **When to use**
|
13
|
+
* - if you need to div-like container to apply padding, shapes, or other styling.
|
14
|
+
* - if you're creating card components.
|
15
|
+
*
|
16
|
+
* **Basic usage**
|
17
|
+
* ```tsx
|
18
|
+
* import { Box } from '@yahoo/uds';
|
19
|
+
*
|
20
|
+
* <Box backgroundColor="primary" spacing="6">
|
21
|
+
* Any kind of content can go here!
|
22
|
+
* </Box>
|
23
|
+
*/
|
24
|
+
declare const Box: react.ForwardRefExoticComponent<BoxProps & react.RefAttributes<HTMLDivElement>>;
|
25
|
+
|
26
|
+
type HtmlButtonProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'color' | 'name'>;
|
27
|
+
interface PressableProps extends UniversalPressableProps, HtmlButtonProps {
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* Provides a primative for creating button interactions with accessibility support.
|
31
|
+
*
|
32
|
+
* **When to use**
|
33
|
+
* - if you need a highly customized version of [Button](./button)
|
34
|
+
*
|
35
|
+
* **Basic usage**
|
36
|
+
* ```tsx
|
37
|
+
* import { Pressable } from '@yahoo/uds';
|
38
|
+
*
|
39
|
+
* <Pressable
|
40
|
+
* backgroundColor="secondary"
|
41
|
+
* borderWidth="thin"
|
42
|
+
* borderColor="primary"
|
43
|
+
* borderRadius="lg"
|
44
|
+
* onPress={() => console.log('Pressed!')}
|
45
|
+
* >
|
46
|
+
* <Text variant="body1" color="primary" spacingHorizontal="7" spacingVertical="5">Click me...</Text>
|
47
|
+
* </Pressable>
|
48
|
+
*/
|
49
|
+
declare const Pressable: react.ForwardRefExoticComponent<PressableProps & react.RefAttributes<HTMLButtonElement>>;
|
50
|
+
|
51
|
+
type TextElementTagName = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'p' | 'strong' | 'span' | 'label' | 'li';
|
52
|
+
type TextProps = UniversalTextProps & {
|
53
|
+
/** Ref passed to the inner container. */
|
54
|
+
ref?: Ref<HTMLElement>;
|
55
|
+
/** Changes the HTML tag used to render text. Uses the most appropriate semantic tag based on the text style variant. */
|
56
|
+
as?: TextElementTagName;
|
57
|
+
} & Omit<JSX.IntrinsicElements[TextElementTagName], 'color'>;
|
58
|
+
/**
|
59
|
+
* A text element that can be used to display text.
|
60
|
+
*
|
61
|
+
* **Basic usage**
|
62
|
+
* ```tsx
|
63
|
+
* import { Text } from '@yahoo/uds';
|
64
|
+
*
|
65
|
+
* <Text variant="body1" color="primary">
|
66
|
+
* Text goes here
|
67
|
+
* </Text>
|
68
|
+
* ```
|
69
|
+
*
|
70
|
+
* By default, the `Text` component uses text primary color and selects the
|
71
|
+
* correct font, weight, and leading. It also choices appropriate semantic
|
72
|
+
* HTML element based on the `variant` prop. For example, `body1` will use a
|
73
|
+
* `<p>` tag, `title1` uses an `<h1>`, etc. This behavior can be overridden
|
74
|
+
* with the `as` prop.
|
75
|
+
*/
|
76
|
+
declare const Text: react.ForwardRefExoticComponent<Omit<TextProps, "ref"> & react.RefAttributes<HTMLElement>>;
|
77
|
+
|
78
|
+
type VStackProps = UniversalStackProps & DivProps;
|
79
|
+
/**
|
80
|
+
* VStack is a layout component that arranges its children in rows using [flexbox](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox)
|
81
|
+
* and can be used to compose larger layouts. VStack is similiar to [Box](./box) but provides additional features like a `gap` property to
|
82
|
+
* add spacing between children.
|
83
|
+
*
|
84
|
+
* **When to use**
|
85
|
+
* - create a column of items, optionally with gaps between.
|
86
|
+
* - create rows that are sized to their content (height only). By default each child will fill the width of the VStack.
|
87
|
+
* - create rows that fill the available space within the parent container.
|
88
|
+
* - create rows of proportionate size to each other (also known as a ratio-based layout).
|
89
|
+
*
|
90
|
+
* **Basic usage**
|
91
|
+
* ```tsx
|
92
|
+
* import { VStack, Text } from '@yahoo/uds';
|
93
|
+
|
94
|
+
* <VStack gap="6">
|
95
|
+
* <Text variant="body1" color="primary">First</Text>
|
96
|
+
* <Text variant="body1" color="primary">Second</Text>
|
97
|
+
* <Text variant="body1" color="primary">Third</Text>
|
98
|
+
* </VStack>
|
99
|
+
* ```
|
100
|
+
**/
|
101
|
+
declare const VStack: react.ForwardRefExoticComponent<UniversalStackProps & DivProps & react.RefAttributes<HTMLDivElement>>;
|
102
|
+
|
103
|
+
export { Box as B, type DivProps as D, Pressable as P, Text as T, VStack as V, type BoxProps as a, type PressableProps as b, type TextProps as c, type VStackProps as d };
|
@@ -0,0 +1,103 @@
|
|
1
|
+
import * as react from 'react';
|
2
|
+
import { Ref } from 'react';
|
3
|
+
import { aS as UniversalBoxProps, i as UniversalPressableProps, aU as UniversalTextProps, l as UniversalStackProps } from './types-COiuE8XK.js';
|
4
|
+
|
5
|
+
type DivProps = React.HTMLAttributes<HTMLDivElement>;
|
6
|
+
interface BoxProps extends UniversalBoxProps, DivProps {
|
7
|
+
}
|
8
|
+
/**
|
9
|
+
* A layout primitive that can be used to compose other components. By default,
|
10
|
+
* `Box` is a flexbox container.
|
11
|
+
*
|
12
|
+
* **When to use**
|
13
|
+
* - if you need to div-like container to apply padding, shapes, or other styling.
|
14
|
+
* - if you're creating card components.
|
15
|
+
*
|
16
|
+
* **Basic usage**
|
17
|
+
* ```tsx
|
18
|
+
* import { Box } from '@yahoo/uds';
|
19
|
+
*
|
20
|
+
* <Box backgroundColor="primary" spacing="6">
|
21
|
+
* Any kind of content can go here!
|
22
|
+
* </Box>
|
23
|
+
*/
|
24
|
+
declare const Box: react.ForwardRefExoticComponent<BoxProps & react.RefAttributes<HTMLDivElement>>;
|
25
|
+
|
26
|
+
type HtmlButtonProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'color' | 'name'>;
|
27
|
+
interface PressableProps extends UniversalPressableProps, HtmlButtonProps {
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* Provides a primative for creating button interactions with accessibility support.
|
31
|
+
*
|
32
|
+
* **When to use**
|
33
|
+
* - if you need a highly customized version of [Button](./button)
|
34
|
+
*
|
35
|
+
* **Basic usage**
|
36
|
+
* ```tsx
|
37
|
+
* import { Pressable } from '@yahoo/uds';
|
38
|
+
*
|
39
|
+
* <Pressable
|
40
|
+
* backgroundColor="secondary"
|
41
|
+
* borderWidth="thin"
|
42
|
+
* borderColor="primary"
|
43
|
+
* borderRadius="lg"
|
44
|
+
* onPress={() => console.log('Pressed!')}
|
45
|
+
* >
|
46
|
+
* <Text variant="body1" color="primary" spacingHorizontal="7" spacingVertical="5">Click me...</Text>
|
47
|
+
* </Pressable>
|
48
|
+
*/
|
49
|
+
declare const Pressable: react.ForwardRefExoticComponent<PressableProps & react.RefAttributes<HTMLButtonElement>>;
|
50
|
+
|
51
|
+
type TextElementTagName = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'p' | 'strong' | 'span' | 'label' | 'li';
|
52
|
+
type TextProps = UniversalTextProps & {
|
53
|
+
/** Ref passed to the inner container. */
|
54
|
+
ref?: Ref<HTMLElement>;
|
55
|
+
/** Changes the HTML tag used to render text. Uses the most appropriate semantic tag based on the text style variant. */
|
56
|
+
as?: TextElementTagName;
|
57
|
+
} & Omit<JSX.IntrinsicElements[TextElementTagName], 'color'>;
|
58
|
+
/**
|
59
|
+
* A text element that can be used to display text.
|
60
|
+
*
|
61
|
+
* **Basic usage**
|
62
|
+
* ```tsx
|
63
|
+
* import { Text } from '@yahoo/uds';
|
64
|
+
*
|
65
|
+
* <Text variant="body1" color="primary">
|
66
|
+
* Text goes here
|
67
|
+
* </Text>
|
68
|
+
* ```
|
69
|
+
*
|
70
|
+
* By default, the `Text` component uses text primary color and selects the
|
71
|
+
* correct font, weight, and leading. It also choices appropriate semantic
|
72
|
+
* HTML element based on the `variant` prop. For example, `body1` will use a
|
73
|
+
* `<p>` tag, `title1` uses an `<h1>`, etc. This behavior can be overridden
|
74
|
+
* with the `as` prop.
|
75
|
+
*/
|
76
|
+
declare const Text: react.ForwardRefExoticComponent<Omit<TextProps, "ref"> & react.RefAttributes<HTMLElement>>;
|
77
|
+
|
78
|
+
type VStackProps = UniversalStackProps & DivProps;
|
79
|
+
/**
|
80
|
+
* VStack is a layout component that arranges its children in rows using [flexbox](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox)
|
81
|
+
* and can be used to compose larger layouts. VStack is similiar to [Box](./box) but provides additional features like a `gap` property to
|
82
|
+
* add spacing between children.
|
83
|
+
*
|
84
|
+
* **When to use**
|
85
|
+
* - create a column of items, optionally with gaps between.
|
86
|
+
* - create rows that are sized to their content (height only). By default each child will fill the width of the VStack.
|
87
|
+
* - create rows that fill the available space within the parent container.
|
88
|
+
* - create rows of proportionate size to each other (also known as a ratio-based layout).
|
89
|
+
*
|
90
|
+
* **Basic usage**
|
91
|
+
* ```tsx
|
92
|
+
* import { VStack, Text } from '@yahoo/uds';
|
93
|
+
|
94
|
+
* <VStack gap="6">
|
95
|
+
* <Text variant="body1" color="primary">First</Text>
|
96
|
+
* <Text variant="body1" color="primary">Second</Text>
|
97
|
+
* <Text variant="body1" color="primary">Third</Text>
|
98
|
+
* </VStack>
|
99
|
+
* ```
|
100
|
+
**/
|
101
|
+
declare const VStack: react.ForwardRefExoticComponent<UniversalStackProps & DivProps & react.RefAttributes<HTMLDivElement>>;
|
102
|
+
|
103
|
+
export { Box as B, type DivProps as D, Pressable as P, Text as T, VStack as V, type BoxProps as a, type PressableProps as b, type TextProps as c, type VStackProps as d };
|