@ornikar/bumper 1.1.0

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 (108) hide show
  1. package/.eslintrc.json +3 -0
  2. package/.vscode/settings.json +3 -0
  3. package/CHANGELOG.md +20 -0
  4. package/dist/definitions/components/breakpoints/SwitchBreakpoins.d.ts +5 -0
  5. package/dist/definitions/components/breakpoints/SwitchBreakpoins.d.ts.map +1 -0
  6. package/dist/definitions/components/breakpoints/hooks/useBreakpointValue.d.ts +3 -0
  7. package/dist/definitions/components/breakpoints/hooks/useBreakpointValue.d.ts.map +1 -0
  8. package/dist/definitions/components/breakpoints/hooks/useCurrentBreakpointName.d.ts +3 -0
  9. package/dist/definitions/components/breakpoints/hooks/useCurrentBreakpointName.d.ts.map +1 -0
  10. package/dist/definitions/components/breakpoints/hooks/useWindowSize.d.ts +2 -0
  11. package/dist/definitions/components/breakpoints/hooks/useWindowSize.d.ts.map +1 -0
  12. package/dist/definitions/components/breakpoints/utils/breakpointsUtils.d.ts +10 -0
  13. package/dist/definitions/components/breakpoints/utils/breakpointsUtils.d.ts.map +1 -0
  14. package/dist/definitions/components/primitives/Stacks.d.ts +9 -0
  15. package/dist/definitions/components/primitives/Stacks.d.ts.map +1 -0
  16. package/dist/definitions/components/primitives/View.d.ts +5 -0
  17. package/dist/definitions/components/primitives/View.d.ts.map +1 -0
  18. package/dist/definitions/components/typography/Typograhy.d.ts +40 -0
  19. package/dist/definitions/components/typography/Typograhy.d.ts.map +1 -0
  20. package/dist/definitions/components/typography/utils/getTypeAndWeightValues.d.ts +9 -0
  21. package/dist/definitions/components/typography/utils/getTypeAndWeightValues.d.ts.map +1 -0
  22. package/dist/definitions/core/BumperDecorator.d.ts +2 -0
  23. package/dist/definitions/core/BumperDecorator.d.ts.map +1 -0
  24. package/dist/definitions/core/BumperProvider.d.ts +6 -0
  25. package/dist/definitions/core/BumperProvider.d.ts.map +1 -0
  26. package/dist/definitions/index.d.ts +10 -0
  27. package/dist/definitions/index.d.ts.map +1 -0
  28. package/dist/definitions/story-components/StorySection.d.ts +20 -0
  29. package/dist/definitions/story-components/StorySection.d.ts.map +1 -0
  30. package/dist/definitions/story-components/StoryTitle.d.ts +6 -0
  31. package/dist/definitions/story-components/StoryTitle.d.ts.map +1 -0
  32. package/dist/definitions/tamagui.config.d.ts +148 -0
  33. package/dist/definitions/tamagui.config.d.ts.map +1 -0
  34. package/dist/definitions/themes/light.d.ts +53 -0
  35. package/dist/definitions/themes/light.d.ts.map +1 -0
  36. package/dist/definitions/themes/palettes/deepPurpleColorPalette.d.ts +86 -0
  37. package/dist/definitions/themes/palettes/deepPurpleColorPalette.d.ts.map +1 -0
  38. package/dist/definitions/themes/utils/breakpoints.d.ts +15 -0
  39. package/dist/definitions/themes/utils/breakpoints.d.ts.map +1 -0
  40. package/dist/definitions/tokens/fonts.d.ts +18 -0
  41. package/dist/definitions/tokens/fonts.d.ts.map +1 -0
  42. package/dist/definitions/tokens/size.d.ts +11 -0
  43. package/dist/definitions/tokens/size.d.ts.map +1 -0
  44. package/dist/definitions/tokens/space.d.ts +16 -0
  45. package/dist/definitions/tokens/space.d.ts.map +1 -0
  46. package/dist/index-metro.es.android.js +396 -0
  47. package/dist/index-metro.es.android.js.map +1 -0
  48. package/dist/index-metro.es.ios.js +396 -0
  49. package/dist/index-metro.es.ios.js.map +1 -0
  50. package/dist/index-node-22.17.cjs.js +405 -0
  51. package/dist/index-node-22.17.cjs.js.map +1 -0
  52. package/dist/index-node-22.17.cjs.web.js +405 -0
  53. package/dist/index-node-22.17.cjs.web.js.map +1 -0
  54. package/dist/index-node-22.17.es.mjs +395 -0
  55. package/dist/index-node-22.17.es.mjs.map +1 -0
  56. package/dist/index-node-22.17.es.web.mjs +395 -0
  57. package/dist/index-node-22.17.es.web.mjs.map +1 -0
  58. package/dist/index.es.js +392 -0
  59. package/dist/index.es.js.map +1 -0
  60. package/dist/index.es.web.js +392 -0
  61. package/dist/index.es.web.js.map +1 -0
  62. package/dist/tsbuildinfo +1 -0
  63. package/package.json +79 -0
  64. package/src/.eslintrc.json +20 -0
  65. package/src/components/breakpoints/SwitchBreakpoins.tsx +12 -0
  66. package/src/components/breakpoints/__snapshots__/breakpoints.stories.tsx.snap +49 -0
  67. package/src/components/breakpoints/__snapshots_web__/breakpoints.stories.tsx.snap +43 -0
  68. package/src/components/breakpoints/breakpoints.stories.tsx +45 -0
  69. package/src/components/breakpoints/hooks/useBreakpointValue.ts +12 -0
  70. package/src/components/breakpoints/hooks/useCurrentBreakpointName.ts +20 -0
  71. package/src/components/breakpoints/hooks/useWindowSize.ts +1 -0
  72. package/src/components/breakpoints/utils/breakpointsUtils.test.ts +85 -0
  73. package/src/components/breakpoints/utils/breakpointsUtils.ts +28 -0
  74. package/src/components/primitives/Stack.stories.tsx +62 -0
  75. package/src/components/primitives/Stacks.ts +19 -0
  76. package/src/components/primitives/View.stories.tsx +13 -0
  77. package/src/components/primitives/View.ts +5 -0
  78. package/src/components/primitives/__snapshots__/Stack.stories.tsx.snap +376 -0
  79. package/src/components/primitives/__snapshots__/View.stories.tsx.snap +25 -0
  80. package/src/components/primitives/__snapshots_web__/Stack.stories.tsx.snap +190 -0
  81. package/src/components/primitives/__snapshots_web__/View.stories.tsx.snap +28 -0
  82. package/src/components/typography/Typograhy.tsx +130 -0
  83. package/src/components/typography/Typography.stories.tsx +144 -0
  84. package/src/components/typography/__snapshots__/Typography.stories.tsx.snap +1471 -0
  85. package/src/components/typography/__snapshots_web__/Typography.stories.tsx.snap +605 -0
  86. package/src/components/typography/utils/getTypeAndWeightValues.test.tsx +147 -0
  87. package/src/components/typography/utils/getTypeAndWeightValues.tsx +32 -0
  88. package/src/core/BumperDecorator.tsx +11 -0
  89. package/src/core/BumperProvider.tsx +15 -0
  90. package/src/index.ts +11 -0
  91. package/src/story-components/StorySection.tsx +70 -0
  92. package/src/story-components/StoryTitle.tsx +16 -0
  93. package/src/tamagui.config.ts +43 -0
  94. package/src/themes/__snapshots__/light.stories.tsx.snap +2192 -0
  95. package/src/themes/__snapshots_web__/light.stories.tsx.snap +985 -0
  96. package/src/themes/light.stories.tsx +38 -0
  97. package/src/themes/light.ts +59 -0
  98. package/src/themes/palettes/__snapshots__/deepPurpleColorPalette.stories.tsx.snap +2770 -0
  99. package/src/themes/palettes/__snapshots_web__/deepPurpleColorPalette.stories.tsx.snap +1213 -0
  100. package/src/themes/palettes/deepPurpleColorPalette.stories.tsx +37 -0
  101. package/src/themes/palettes/deepPurpleColorPalette.ts +147 -0
  102. package/src/themes/utils/breakpoints.ts +15 -0
  103. package/src/tokens/fonts.ts +95 -0
  104. package/src/tokens/size.ts +10 -0
  105. package/src/tokens/space.ts +15 -0
  106. package/tsconfig.build.json +25 -0
  107. package/tsconfig.eslint.json +6 -0
  108. package/tsconfig.json +21 -0
@@ -0,0 +1,130 @@
1
+ import type { GetProps, GetThemeValueForKey } from '@tamagui/core';
2
+ import { Text, styled } from '@tamagui/core';
3
+ import { createContext, useContext } from 'react';
4
+ import { type Except } from 'type-fest';
5
+ import type { BodyFontVariants, FontVariants, HeadingFontVariants, LabelFontVariants } from '../../tokens/fonts';
6
+ import { getVariantAndWeightValues } from './utils/getTypeAndWeightValues';
7
+
8
+ export type TypographyVariantContextValue = FontVariants | null;
9
+ export type TypographyWeightContextValue = 'regular' | 'bold' | null;
10
+ export type TypograhyColorContextValue = TypograhyColorProps | null;
11
+
12
+ const TypographyVariantContext = createContext<TypographyVariantContextValue>(null);
13
+ const TypographyWeightContext = createContext<TypographyWeightContextValue>(null);
14
+ const TypograhyColorContext = createContext<TypograhyColorContextValue>(null);
15
+
16
+ const InternalTypography = styled(Text, {
17
+ fontFamily: '$GTStandard',
18
+ color: '$content.base.hi',
19
+ '$platform-web': {
20
+ WebkitFontSmoothing: 'antialiased',
21
+ },
22
+ variants: {
23
+ variant: (variant: FontVariants | undefined) => {
24
+ if (!variant) return {};
25
+
26
+ return {
27
+ fontSize: `$${variant}`,
28
+ lineHeight: `$${variant}`,
29
+ letterSpacing: `$${variant}`,
30
+ };
31
+ },
32
+ weight: {
33
+ regular: {
34
+ fontWeight: '$regular',
35
+ },
36
+ semibold: {
37
+ fontWeight: '$semibold',
38
+ },
39
+ bold: {
40
+ fontWeight: '$bold',
41
+ },
42
+ },
43
+ } as const,
44
+ defaultVariants: {
45
+ variant: 'body-m',
46
+ weight: 'regular',
47
+ },
48
+ });
49
+
50
+ export type InternalTypographyProps = GetProps<typeof InternalTypography>;
51
+
52
+ // Create a type for color props that matches strings containing '$content.'
53
+ type ContainsOneString<T extends string> = `${string}${T}${string}`;
54
+ type TypograhyColorProps = ContainsOneString<'$content.'>;
55
+
56
+ // Remove font-related style props from InternalTypography Props
57
+ type TypographyExcludedFontStyleProps =
58
+ | 'fontFamily'
59
+ | 'fontSize'
60
+ | 'lineHeight'
61
+ | 'fontStyle'
62
+ | 'fontVariant'
63
+ | 'fontWeight';
64
+ type TypographyPropsWithoutFontStyleProps = Except<
65
+ InternalTypographyProps,
66
+ TypographyExcludedFontStyleProps | 'color'
67
+ > & {
68
+ color?: TypograhyColorProps;
69
+ };
70
+
71
+ export interface BodyProps extends TypographyPropsWithoutFontStyleProps {
72
+ variant?: BodyFontVariants;
73
+ weight?: Exclude<InternalTypographyProps['weight'], 'semibold'>;
74
+ }
75
+ export interface HeadingLabelProps extends TypographyPropsWithoutFontStyleProps {
76
+ variant: HeadingFontVariants | LabelFontVariants;
77
+ weight?: never;
78
+ }
79
+ export type TypographyTextProps = BodyProps | HeadingLabelProps;
80
+
81
+ const TypographyText = InternalTypography.styleable<TypographyTextProps>((props, ref) => {
82
+ const typographyVariantAncestorValue = useContext(TypographyVariantContext);
83
+ const typographyWeightAncestorValue = useContext(TypographyWeightContext);
84
+ const typographyColorAncestorValue = useContext(TypograhyColorContext);
85
+
86
+ const { variant, weight } = getVariantAndWeightValues(
87
+ props.weight,
88
+ props.variant,
89
+ typographyWeightAncestorValue,
90
+ typographyVariantAncestorValue,
91
+ );
92
+ const color = props.color || typographyColorAncestorValue || undefined;
93
+
94
+ let content = (
95
+ <InternalTypography
96
+ ref={ref}
97
+ {...props}
98
+ color={color as GetThemeValueForKey<'color'>}
99
+ weight={weight}
100
+ variant={variant}
101
+ />
102
+ );
103
+
104
+ content = props.variant ? (
105
+ // If a variant is provided, we set it in the context for children to be able to inherit variant value
106
+ <TypographyVariantContext.Provider value={props.variant}>{content}</TypographyVariantContext.Provider>
107
+ ) : (
108
+ content
109
+ );
110
+
111
+ content = props.weight ? (
112
+ // If a weight is provided, we set it in the context for children to be able to inherit weight value
113
+ <TypographyWeightContext.Provider value={props.weight}>{content}</TypographyWeightContext.Provider>
114
+ ) : (
115
+ content
116
+ );
117
+
118
+ content = props.color ? (
119
+ // If a color is provided, we set it in the context for children to be able to inherit color value
120
+ <TypograhyColorContext.Provider value={props.color}>{content}</TypograhyColorContext.Provider>
121
+ ) : (
122
+ content
123
+ );
124
+
125
+ return content;
126
+ });
127
+
128
+ export const Typography = {
129
+ Text: TypographyText,
130
+ };
@@ -0,0 +1,144 @@
1
+ import type { ComponentStory, Meta } from '@storybook/react';
2
+ import type { FC } from 'react';
3
+ import { StorySection } from '../../story-components/StorySection';
4
+ import type { BodyFontVariants, FontVariants, HeadingFontVariants, LabelFontVariants } from '../../tokens/fonts';
5
+ import { VStack } from '../primitives/Stacks';
6
+ import { View } from '../primitives/View';
7
+ import type { TypographyTextProps } from './Typograhy';
8
+ import { Typography } from './Typograhy';
9
+
10
+ export default {
11
+ title: 'bumper/Typography/Typography',
12
+ component: Typography.Text,
13
+ } satisfies Meta<typeof Typography.Text>;
14
+
15
+ interface TypographyTypeWithComponent<T extends FontVariants> {
16
+ component: FC<TypographyTextProps>;
17
+ variant: T;
18
+ weights: TypographyTextProps['weight'][];
19
+ }
20
+
21
+ const headingVariants: TypographyTypeWithComponent<HeadingFontVariants>[] = [
22
+ { component: Typography.Text, variant: 'heading-2xl', weights: [undefined] },
23
+ { component: Typography.Text, variant: 'heading-xl', weights: [undefined] },
24
+ { component: Typography.Text, variant: 'heading-l', weights: [undefined] },
25
+ { component: Typography.Text, variant: 'heading-m', weights: [undefined] },
26
+ { component: Typography.Text, variant: 'heading-s', weights: [undefined] },
27
+ { component: Typography.Text, variant: 'heading-xs', weights: [undefined] },
28
+ ];
29
+
30
+ const bodyVariants: TypographyTypeWithComponent<BodyFontVariants>[] = [
31
+ { component: Typography.Text, variant: 'body-xl', weights: ['bold', 'regular'] },
32
+ { component: Typography.Text, variant: 'body-l', weights: ['bold', 'regular'] },
33
+ { component: Typography.Text, variant: 'body-m', weights: ['bold', 'regular'] },
34
+ { component: Typography.Text, variant: 'body-s', weights: ['bold', 'regular'] },
35
+ { component: Typography.Text, variant: 'body-xs', weights: ['bold', 'regular'] },
36
+ ];
37
+
38
+ const labelVariants: TypographyTypeWithComponent<LabelFontVariants>[] = [
39
+ { component: Typography.Text, variant: 'label-xl', weights: [undefined] },
40
+ { component: Typography.Text, variant: 'label-l', weights: [undefined] },
41
+ { component: Typography.Text, variant: 'label-m', weights: [undefined] },
42
+ { component: Typography.Text, variant: 'label-s', weights: [undefined] },
43
+ ];
44
+
45
+ interface TypographyTypesProps {
46
+ types: TypographyTypeWithComponent<FontVariants>[];
47
+ }
48
+
49
+ function TypographyVariants({ types }: TypographyTypesProps) {
50
+ return (
51
+ <>
52
+ {types.map((type) => {
53
+ return type.weights.map((weight) => (
54
+ <VStack key={`${type.variant}-${weight}`} marginBottom="$size.20">
55
+ <Typography.Text variant="heading-s">{`${type.variant.split('-').join(' ')} - ${
56
+ weight || 'semibold'
57
+ }`}</Typography.Text>
58
+ <View
59
+ paddingVertical="$space.4"
60
+ paddingHorizontal="$space.8"
61
+ borderRadius="$space.4"
62
+ backgroundColor="$bg.base.mid.default"
63
+ marginTop="$space.4"
64
+ >
65
+ {/* Don't know why it's expecting BodyFontVariants type */}
66
+ <Typography.Text variant={type.variant as BodyFontVariants} weight={weight}>
67
+ The quick brown fox jumps over the lazy dog
68
+ </Typography.Text>
69
+ </View>
70
+ </VStack>
71
+ ));
72
+ })}
73
+ </>
74
+ );
75
+ }
76
+
77
+ export const TypographyStory: ComponentStory<typeof Typography.Text> = (args) => (
78
+ <>
79
+ <StorySection.Demo>
80
+ <Typography.Text {...args} />
81
+ </StorySection.Demo>
82
+ <StorySection title="Inheritance">
83
+ <StorySection.SubSection title="Type inheritance">
84
+ <Typography.Text variant="body-l">
85
+ Type is body-l{' '}
86
+ <Typography.Text variant="heading-l">
87
+ type is heading-l <Typography.Text color="$content.accent">type is undefined</Typography.Text>
88
+ </Typography.Text>{' '}
89
+ <Typography.Text color="$content.danger">
90
+ type is undefined <Typography.Text variant="body-s">Type is body-s</Typography.Text>
91
+ </Typography.Text>
92
+ .
93
+ </Typography.Text>
94
+ </StorySection.SubSection>
95
+ <StorySection.SubSection title="Weight inheritance">
96
+ <Typography.Text>
97
+ weight is undefined{' '}
98
+ <Typography.Text weight="bold">
99
+ weight is bold{' '}
100
+ <Typography.Text variant="heading-m">
101
+ weight is undefined and type is heading-m{' '}
102
+ <Typography.Text variant="body-m" weight="regular">
103
+ weight is regular <Typography.Text weight="bold">weight is bold</Typography.Text>
104
+ </Typography.Text>
105
+ </Typography.Text>
106
+ </Typography.Text>{' '}
107
+ </Typography.Text>
108
+ </StorySection.SubSection>
109
+ <StorySection.SubSection title="Color inheritance">
110
+ <Typography.Text>
111
+ color is undefined{' '}
112
+ <Typography.Text color="$content.accent">
113
+ color is $content.accent{' '}
114
+ <Typography.Text>
115
+ color is undefined{' '}
116
+ <Typography.Text color="$content.danger">
117
+ color is content.danger{' '}
118
+ <Typography.Text color="$content.base.hi">color is content.base.hi</Typography.Text>
119
+ </Typography.Text>
120
+ </Typography.Text>
121
+ </Typography.Text>{' '}
122
+ </Typography.Text>
123
+ </StorySection.SubSection>
124
+ <StorySection title="Heading">
125
+ <TypographyVariants types={headingVariants} />
126
+ </StorySection>
127
+ <StorySection title="Body">
128
+ <TypographyVariants types={bodyVariants} />
129
+ </StorySection>
130
+ <StorySection title="Label">
131
+ <TypographyVariants types={labelVariants} />
132
+ </StorySection>
133
+ </StorySection>
134
+ </>
135
+ );
136
+
137
+ TypographyStory.storyName = 'Typography';
138
+
139
+ TypographyStory.args = {
140
+ children: 'Hello World',
141
+ color: '$content.base.hi',
142
+ weight: 'regular',
143
+ variant: 'body-m',
144
+ };