onecart-ui 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +351 -0
  2. package/dist/components/Button/Button.d.ts +4 -0
  3. package/dist/components/Button/Button.d.ts.map +1 -0
  4. package/dist/components/Button/index.d.ts +3 -0
  5. package/dist/components/Button/index.d.ts.map +1 -0
  6. package/dist/components/Heading/Heading.d.ts +5 -0
  7. package/dist/components/Heading/Heading.d.ts.map +1 -0
  8. package/dist/components/Heading/index.d.ts +3 -0
  9. package/dist/components/Heading/index.d.ts.map +1 -0
  10. package/dist/components/Paragraph/Paragraph.d.ts +5 -0
  11. package/dist/components/Paragraph/Paragraph.d.ts.map +1 -0
  12. package/dist/components/Paragraph/index.d.ts +3 -0
  13. package/dist/components/Paragraph/index.d.ts.map +1 -0
  14. package/dist/components/Text/Text.d.ts +5 -0
  15. package/dist/components/Text/Text.d.ts.map +1 -0
  16. package/dist/components/Text/index.d.ts +3 -0
  17. package/dist/components/Text/index.d.ts.map +1 -0
  18. package/dist/components/Typography/Typography.d.ts +5 -0
  19. package/dist/components/Typography/Typography.d.ts.map +1 -0
  20. package/dist/components/Typography/index.d.ts +3 -0
  21. package/dist/components/Typography/index.d.ts.map +1 -0
  22. package/dist/index.d.ts +13 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.esm.js +2 -0
  25. package/dist/index.esm.js.map +1 -0
  26. package/dist/index.js +2 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/styles/tokens/index.d.ts +107 -0
  29. package/dist/styles/tokens/index.d.ts.map +1 -0
  30. package/dist/styles/tokens/tokens.d.ts +350 -0
  31. package/dist/styles/tokens/tokens.d.ts.map +1 -0
  32. package/dist/styles/tokens/typography.d.ts +154 -0
  33. package/dist/styles/tokens/typography.d.ts.map +1 -0
  34. package/dist/styles/tokens/utils/fontUtils.d.ts +26 -0
  35. package/dist/styles/tokens/utils/fontUtils.d.ts.map +1 -0
  36. package/dist/styles/tokens/utils/utils.d.ts +13 -0
  37. package/dist/styles/tokens/utils/utils.d.ts.map +1 -0
  38. package/dist/theme/ThemeProvider.d.ts +14 -0
  39. package/dist/theme/ThemeProvider.d.ts.map +1 -0
  40. package/dist/theme/index.d.ts +55 -0
  41. package/dist/theme/index.d.ts.map +1 -0
  42. package/dist/types/Button.d.ts +47 -0
  43. package/dist/types/Button.d.ts.map +1 -0
  44. package/dist/types/Heading.d.ts +24 -0
  45. package/dist/types/Heading.d.ts.map +1 -0
  46. package/dist/types/Paragraph.d.ts +35 -0
  47. package/dist/types/Paragraph.d.ts.map +1 -0
  48. package/dist/types/Text.d.ts +32 -0
  49. package/dist/types/Text.d.ts.map +1 -0
  50. package/dist/types/Typography.d.ts +64 -0
  51. package/dist/types/Typography.d.ts.map +1 -0
  52. package/package.json +72 -0
  53. package/src/components/Button/Button.tsx +155 -0
  54. package/src/components/Button/index.ts +2 -0
  55. package/src/components/Heading/Heading.tsx +48 -0
  56. package/src/components/Heading/index.ts +2 -0
  57. package/src/components/Paragraph/Paragraph.tsx +93 -0
  58. package/src/components/Paragraph/index.ts +6 -0
  59. package/src/components/Text/Text.tsx +96 -0
  60. package/src/components/Text/index.ts +2 -0
  61. package/src/components/Typography/Typography.tsx +123 -0
  62. package/src/components/Typography/index.ts +7 -0
  63. package/src/index.ts +34 -0
  64. package/src/styles/tokens/index.ts +130 -0
  65. package/src/styles/tokens/tokens-autocomplete-config.json +2417 -0
  66. package/src/styles/tokens/tokens.css +352 -0
  67. package/src/styles/tokens/tokens.js +350 -0
  68. package/src/styles/tokens/tokens.json +427 -0
  69. package/src/styles/tokens/tokens.less +349 -0
  70. package/src/styles/tokens/tokens.scss +349 -0
  71. package/src/styles/tokens/tokens.ts +350 -0
  72. package/src/styles/tokens/tokensMap.scss +353 -0
  73. package/src/styles/tokens/typography.ts +172 -0
  74. package/src/styles/tokens/utils/fontUtils.ts +63 -0
  75. package/src/styles/tokens/utils/utils.ts +19 -0
  76. package/src/theme/ThemeProvider.tsx +71 -0
  77. package/src/theme/index.ts +107 -0
  78. package/src/types/Button.ts +56 -0
  79. package/src/types/Heading.ts +27 -0
  80. package/src/types/Paragraph.ts +40 -0
  81. package/src/types/Text.ts +40 -0
  82. package/src/types/Typography.ts +94 -0
@@ -0,0 +1,96 @@
1
+ import React from "react";
2
+ import { TouchableOpacity, TextStyle, View } from "react-native";
3
+ import * as tokens from "../../styles/tokens/tokens";
4
+ import { Typography } from "../Typography";
5
+ import { useTheme } from "../../theme/ThemeProvider";
6
+ import { TextProps } from "../../types/Text";
7
+
8
+ export const Text: React.FC<TextProps> = ({
9
+ children,
10
+ variant = "bodyMd",
11
+ align,
12
+ weight,
13
+ color,
14
+ underline = false,
15
+ strikethrough = false,
16
+ italic = false,
17
+ link = false,
18
+ onLinkPress,
19
+ style,
20
+ ...rest
21
+ }) => {
22
+ const { theme } = useTheme();
23
+
24
+ const getTextDecorations = React.useMemo((): TextStyle => {
25
+ const decorations: TextStyle = {};
26
+
27
+ if (underline) {
28
+ decorations.textDecorationLine = "underline";
29
+ }
30
+
31
+ if (strikethrough) {
32
+ decorations.textDecorationLine = decorations.textDecorationLine
33
+ ? "underline line-through"
34
+ : "line-through";
35
+ }
36
+
37
+ if (italic) {
38
+ decorations.fontStyle = "italic";
39
+ }
40
+
41
+ if (link) {
42
+ const linkColor = color || theme.colors?.primary || tokens.TEXT_BLUE;
43
+ decorations.color = linkColor;
44
+
45
+ decorations.textDecorationLine = underline
46
+ ? "underline"
47
+ : decorations.textDecorationLine || tokens.TEXT_DECORATION_NONE;
48
+ }
49
+
50
+ return decorations;
51
+ }, [underline, strikethrough, italic, link, color, theme]);
52
+
53
+ const combinedStyle = React.useMemo(
54
+ () => ({
55
+ ...getTextDecorations,
56
+ ...style,
57
+ }),
58
+ [getTextDecorations, style]
59
+ );
60
+
61
+ if (link && onLinkPress) {
62
+ return (
63
+ <TouchableOpacity
64
+ onPress={onLinkPress}
65
+ accessibilityRole="link"
66
+ activeOpacity={0.7}
67
+ >
68
+ <Typography
69
+ variant={variant}
70
+ align={align}
71
+ weight={weight}
72
+ color={color || theme.colors?.primary || tokens.TEXT_BLUE}
73
+ style={combinedStyle}
74
+ {...rest}
75
+ >
76
+ {children}
77
+ </Typography>
78
+ </TouchableOpacity>
79
+ );
80
+ }
81
+
82
+ return (
83
+ <Typography
84
+ variant={variant}
85
+ align={align}
86
+ weight={weight}
87
+ color={color}
88
+ style={combinedStyle}
89
+ {...rest}
90
+ >
91
+ {children}
92
+ </Typography>
93
+ );
94
+ };
95
+
96
+ export default Text;
@@ -0,0 +1,2 @@
1
+ export { Text } from "./Text";
2
+ export type { TextProps } from "../../types/Text";
@@ -0,0 +1,123 @@
1
+ import React from "react";
2
+ import { Text, TextStyle } from "react-native";
3
+ import { typographyTokens } from "../../styles/tokens";
4
+ import * as tokens from "../../styles/tokens/tokens";
5
+ import { useTheme } from "../../theme/ThemeProvider";
6
+ import { letterSpacingToPixels } from "../../styles/tokens/utils/fontUtils";
7
+ import { TypographyProps } from "../../types/Typography";
8
+
9
+ export const Typography: React.FC<TypographyProps> = ({
10
+ children,
11
+ variant = "bodyMd",
12
+ align = "left",
13
+ weight,
14
+ color,
15
+ truncate = false,
16
+ numberOfLines,
17
+ style,
18
+ accessibilityLabel,
19
+ testID,
20
+ ...rest
21
+ }) => {
22
+ const { theme } = useTheme();
23
+
24
+ const getTypographyStyles = React.useMemo((): TextStyle => {
25
+ try {
26
+ const variantStyle = typographyTokens[variant];
27
+
28
+ const textAlign = align;
29
+
30
+ const fontWeight = weight
31
+ ? typographyTokens.weights[weight]
32
+ : variantStyle.fontWeight;
33
+
34
+ let defaultColor = variantStyle.color;
35
+ if (theme?.colors?.text && typeof theme.colors.text === "object") {
36
+ const themeTextColor = (theme.colors.text as Record<string, string>)[
37
+ variant
38
+ ];
39
+ if (themeTextColor) {
40
+ defaultColor = themeTextColor;
41
+ }
42
+ }
43
+ const textColor = color || defaultColor;
44
+
45
+ // Create style object
46
+ const styles: TextStyle = {
47
+ fontFamily: variantStyle.fontFamily,
48
+ fontSize: variantStyle.fontSize,
49
+ fontWeight: fontWeight as any,
50
+ lineHeight: variantStyle.lineHeight,
51
+ color: textColor,
52
+ textAlign,
53
+ };
54
+
55
+ if (variantStyle.letterSpacing) {
56
+ styles.letterSpacing = letterSpacingToPixels(
57
+ variantStyle.letterSpacing.toString(),
58
+ variantStyle.fontSize
59
+ );
60
+ }
61
+
62
+ if (
63
+ variantStyle.textDecoration &&
64
+ variantStyle.textDecoration !== "none"
65
+ ) {
66
+ styles.textDecorationLine = variantStyle.textDecoration as any;
67
+ }
68
+
69
+ if (variantStyle.textCase && variantStyle.textCase !== "none") {
70
+ if (variantStyle.textCase === "uppercase") {
71
+ styles.textTransform = "uppercase";
72
+ } else if (variantStyle.textCase === "lowercase") {
73
+ styles.textTransform = "lowercase";
74
+ } else if (variantStyle.textCase === "capitalize") {
75
+ styles.textTransform = "capitalize";
76
+ }
77
+ }
78
+
79
+ return styles;
80
+ } catch (error) {
81
+ return {
82
+ fontSize: 16,
83
+ fontWeight: "400",
84
+ lineHeight: 24,
85
+ color: tokens.TEXT_BODY || "#000000",
86
+ textAlign: align,
87
+ };
88
+ }
89
+ }, [variant, align, weight, color, theme]);
90
+
91
+ const textStyles = React.useMemo((): TextStyle => {
92
+ const combinedStyles: TextStyle = { ...getTypographyStyles };
93
+
94
+ if (truncate) {
95
+ const webStyles: any = {
96
+ overflow: "hidden",
97
+ textOverflow: "ellipsis",
98
+ whiteSpace: "nowrap",
99
+ };
100
+ Object.assign(combinedStyles, webStyles);
101
+ }
102
+
103
+ if (style) {
104
+ Object.assign(combinedStyles, style);
105
+ }
106
+
107
+ return combinedStyles;
108
+ }, [getTypographyStyles, truncate, style]);
109
+
110
+ return (
111
+ <Text
112
+ style={textStyles}
113
+ numberOfLines={numberOfLines || (truncate ? 1 : undefined)}
114
+ accessibilityLabel={accessibilityLabel}
115
+ testID={testID}
116
+ {...rest}
117
+ >
118
+ {children}
119
+ </Text>
120
+ );
121
+ };
122
+
123
+ export default Typography;
@@ -0,0 +1,7 @@
1
+ export { Typography } from "./Typography";
2
+ export type {
3
+ TypographyProps,
4
+ TypographyVariant,
5
+ TypographyAlign,
6
+ TypographyWeight,
7
+ } from "../../types/Typography";
package/src/index.ts ADDED
@@ -0,0 +1,34 @@
1
+ // Components
2
+ export { Button } from "./components/Button";
3
+ export { Typography } from "./components/Typography";
4
+ export { Text } from "./components/Text";
5
+ export { Heading } from "./components/Heading";
6
+ export { Paragraph } from "./components/Paragraph";
7
+
8
+ // Types
9
+ export type { ButtonProps } from "./types/Button";
10
+ export type {
11
+ TypographyProps,
12
+ TypographyVariant,
13
+ TypographyAlign,
14
+ TypographyWeight,
15
+ } from "./types/Typography";
16
+ export type { TextProps } from "./types/Text";
17
+ export type { HeadingProps, HeadingLevel } from "./types/Heading";
18
+ export type {
19
+ ParagraphProps,
20
+ ParagraphSize,
21
+ ParagraphSpacing,
22
+ } from "./types/Paragraph";
23
+
24
+ // Theme
25
+ export { ThemeProvider, useTheme } from "./theme/ThemeProvider";
26
+
27
+ export {
28
+ defaultTheme,
29
+ type Theme,
30
+ type ThemeColors,
31
+ type ThemeSpacing,
32
+ type ThemeBorderRadius,
33
+ type ThemeTypography,
34
+ } from "./theme";
@@ -0,0 +1,130 @@
1
+ // This file maps the generated tokens to a structured format our components expect
2
+ import * as tokens from './tokens';
3
+ import { typographyTokens } from './typography';
4
+
5
+ export { typographyTokens };
6
+
7
+ // Convert rem values to numbers
8
+ const remToNumber = (remValue: string): number => {
9
+ if (!remValue || typeof remValue !== 'string') return 0;
10
+ return parseFloat(remValue.replace('rem', '')) * 16; // Assuming 1rem = 16px
11
+ };
12
+
13
+ // Convert px values to numbers
14
+ const pxToNumber = (pxValue: string): number => {
15
+ if (!pxValue || typeof pxValue !== 'string') return 0;
16
+ return parseFloat(pxValue.replace('px', ''));
17
+ };
18
+
19
+ // Size configurations for buttons
20
+ const buttonSizes = {
21
+ sm: {
22
+ paddingHorizontal: remToNumber(tokens.LAYOUT_SPACING_INLINE_SM),
23
+ paddingVertical: remToNumber(tokens.LAYOUT_SPACING_STACK_XS),
24
+ fontSize: pxToNumber(tokens.FONT_SIZE_3XS),
25
+ borderRadius: remToNumber(tokens.BORDER_RADIUS_BUTTON_SM),
26
+ minHeight: 32,
27
+ },
28
+ md: {
29
+ paddingHorizontal: remToNumber(tokens.LAYOUT_SPACING_INLINE_MD),
30
+ paddingVertical: remToNumber(tokens.LAYOUT_SPACING_STACK_SM),
31
+ fontSize: pxToNumber(tokens.FONT_SIZE_XS),
32
+ borderRadius: remToNumber(tokens.BORDER_RADIUS_XS),
33
+ minHeight: 40,
34
+ },
35
+ lg: {
36
+ paddingHorizontal: remToNumber(tokens.LAYOUT_SPACING_INLINE_LG),
37
+ paddingVertical: remToNumber(tokens.LAYOUT_SPACING_STACK_MD),
38
+ fontSize: pxToNumber(tokens.FONT_SIZE_MD),
39
+ borderRadius: remToNumber(tokens.BORDER_RADIUS_SM),
40
+ minHeight: 48,
41
+ }
42
+ };
43
+
44
+ // Common button properties
45
+ const buttonCommon = {
46
+ fontWeight: tokens.MEDIUM,
47
+ lineHeight: pxToNumber(tokens.LINE_HEIGHT_XS),
48
+ borderWidth: pxToNumber(tokens.BORDER_WIDTH_BUTTON_DEFAULT),
49
+ transition: 'all 0.2s ease-in-out',
50
+ };
51
+
52
+ // Button tokens organized by variant and size
53
+ export const buttonTokens = {
54
+ primary: {
55
+ background: {
56
+ default: tokens.ACTION_PRIMARY_DEFAULT,
57
+ hover: tokens.ACTION_PRIMARY_HOVER,
58
+ active: tokens.ACTION_PRIMARY_ACTIVE,
59
+ disabled: tokens.ACTION_PRIMARY_DISABLED,
60
+ },
61
+ text: {
62
+ default: "#FFFFFF", // White
63
+ disabled: tokens.NEUTRAL_50,
64
+ },
65
+ border: {
66
+ default: tokens.ACTION_PRIMARY_DEFAULT,
67
+ hover: tokens.ACTION_PRIMARY_HOVER,
68
+ active: tokens.ACTION_PRIMARY_ACTIVE,
69
+ disabled: tokens.ACTION_PRIMARY_DISABLED,
70
+ }
71
+ },
72
+ secondary: {
73
+ background: {
74
+ default: tokens.NEUTRAL_10,
75
+ hover: tokens.NEUTRAL_20,
76
+ active: tokens.NEUTRAL_30,
77
+ disabled: tokens.NEUTRAL_10,
78
+ },
79
+ text: {
80
+ default: tokens.NEUTRAL_70,
81
+ disabled: tokens.NEUTRAL_40,
82
+ },
83
+ border: {
84
+ default: tokens.NEUTRAL_30,
85
+ hover: tokens.NEUTRAL_40,
86
+ active: tokens.NEUTRAL_50,
87
+ disabled: tokens.NEUTRAL_20,
88
+ }
89
+ },
90
+ outline: {
91
+ background: {
92
+ default: 'transparent',
93
+ hover: tokens.ACTION_PRIMARY_DISABLED,
94
+ active: tokens.ACTION_PRIMARY_ACTIVE,
95
+ disabled: 'transparent',
96
+ },
97
+ text: {
98
+ default: tokens.ACTION_PRIMARY_DEFAULT,
99
+ disabled: tokens.NEUTRAL_40,
100
+ },
101
+ border: {
102
+ default: tokens.ACTION_PRIMARY_DEFAULT,
103
+ hover: tokens.ACTION_PRIMARY_HOVER,
104
+ active: tokens.ACTION_PRIMARY_ACTIVE,
105
+ disabled: tokens.NEUTRAL_30,
106
+ }
107
+ },
108
+ ghost: {
109
+ background: {
110
+ default: 'transparent',
111
+ hover: tokens.NEUTRAL_10,
112
+ active: tokens.NEUTRAL_20,
113
+ disabled: 'transparent',
114
+ },
115
+ text: {
116
+ default: tokens.NEUTRAL_60,
117
+ disabled: tokens.NEUTRAL_40,
118
+ },
119
+ border: {
120
+ default: 'transparent',
121
+ hover: 'transparent',
122
+ active: 'transparent',
123
+ disabled: 'transparent',
124
+ }
125
+ },
126
+ sizes: buttonSizes,
127
+ common: buttonCommon
128
+ };
129
+
130
+ export default buttonTokens;