@apify/ui-library 0.71.1-featcolortokens-178953.63 → 0.71.1-featcolortokens-178953.70

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 (86) hide show
  1. package/dist/tsconfig.build.tsbuildinfo +1 -1
  2. package/package.json +3 -2
  3. package/src/codemods/generate_typograpy_tokens_files.mjs +137 -0
  4. package/src/components/action_link.tsx +60 -0
  5. package/src/components/actor_template_card.tsx +116 -0
  6. package/src/components/badge.tsx +148 -0
  7. package/src/components/banner.tsx +94 -0
  8. package/src/components/blog_article.tsx +85 -0
  9. package/src/components/box.tsx +127 -0
  10. package/src/components/button.tsx +305 -0
  11. package/src/components/chip.tsx +128 -0
  12. package/src/components/code/action_button.tsx +96 -0
  13. package/src/components/code/code_block/code_block.styled.tsx +180 -0
  14. package/src/components/code/code_block/code_block.tsx +224 -0
  15. package/src/components/code/code_block/code_block_with_tabs.tsx +257 -0
  16. package/src/components/code/code_block/utils.tsx +67 -0
  17. package/src/components/code/index.ts +5 -0
  18. package/src/components/code/inline_code/inline_code.tsx +62 -0
  19. package/src/components/code/one_line_code/one_line_code.tsx +228 -0
  20. package/src/components/code/prism_highlighter.tsx +180 -0
  21. package/src/components/color_wheel_gradient.tsx +31 -0
  22. package/src/components/floating/index.ts +3 -0
  23. package/src/components/floating/menu.tsx +189 -0
  24. package/src/components/floating/menu_common.tsx +31 -0
  25. package/src/components/floating/menu_components.tsx +99 -0
  26. package/src/components/image.tsx +24 -0
  27. package/src/components/index.ts +22 -0
  28. package/src/components/link.tsx +114 -0
  29. package/src/components/message.tsx +153 -0
  30. package/src/components/rating.tsx +106 -0
  31. package/src/components/readme_renderer/index.ts +3 -0
  32. package/src/components/readme_renderer/pythonize_value.ts +76 -0
  33. package/src/components/readme_renderer/table_of_contents.tsx +272 -0
  34. package/src/components/readme_renderer/utils.tsx +46 -0
  35. package/src/components/simple_markdown/index.ts +2 -0
  36. package/src/components/simple_markdown/simple_markdown.tsx +214 -0
  37. package/src/components/simple_markdown/simple_markdown_components.tsx +293 -0
  38. package/src/components/tabs/index.ts +2 -0
  39. package/src/components/tabs/tab.tsx +217 -0
  40. package/src/components/tabs/tabs.tsx +169 -0
  41. package/src/components/tag.tsx +196 -0
  42. package/src/components/text/heading_content.tsx +56 -0
  43. package/src/components/text/heading_marketing.tsx +55 -0
  44. package/src/components/text/heading_shared.tsx +55 -0
  45. package/src/components/text/index.ts +19 -0
  46. package/src/components/text/text_base.tsx +52 -0
  47. package/src/components/text/text_content.tsx +104 -0
  48. package/src/components/text/text_marketing.tsx +152 -0
  49. package/src/components/text/text_shared.tsx +95 -0
  50. package/src/components/tile/horizontal_tile.tsx +77 -0
  51. package/src/components/tile/index.ts +2 -0
  52. package/src/components/tile/shared.ts +27 -0
  53. package/src/components/tile/vertical_tile.tsx +59 -0
  54. package/src/components/to_consolidate/card.tsx +141 -0
  55. package/src/components/to_consolidate/index.ts +4 -0
  56. package/src/components/to_consolidate/markdown.tsx +609 -0
  57. package/src/components/to_consolidate/pagination.tsx +136 -0
  58. package/src/components/to_consolidate/tab_number_chip.tsx +31 -0
  59. package/src/design_system/colors/build_color_tokens.js +183 -0
  60. package/src/design_system/colors/figma_color_tokens.dark.json +886 -0
  61. package/src/design_system/colors/figma_color_tokens.light.json +886 -0
  62. package/src/design_system/colors/generated/colors_theme.dark.ts +110 -0
  63. package/src/design_system/colors/generated/colors_theme.light.ts +110 -0
  64. package/src/design_system/colors/generated/css_variables.dark.ts +147 -0
  65. package/src/design_system/colors/generated/css_variables.light.ts +147 -0
  66. package/src/design_system/colors/generated/css_variables_palette.dark.ts +74 -0
  67. package/src/design_system/colors/generated/css_variables_palette.light.ts +74 -0
  68. package/src/design_system/colors/generated/properties_theme.ts +179 -0
  69. package/src/design_system/colors/index.ts +7 -0
  70. package/src/design_system/supernova_typography_tokens.json +657 -0
  71. package/src/design_system/theme.ts +25 -0
  72. package/src/design_system/tokens/index.ts +5 -0
  73. package/src/design_system/tokens/layouts.ts +29 -0
  74. package/src/design_system/tokens/radiuses.ts +22 -0
  75. package/src/design_system/tokens/shadows.ts +22 -0
  76. package/src/design_system/tokens/spaces.ts +15 -0
  77. package/src/design_system/tokens/transitions.ts +19 -0
  78. package/src/design_system/typography_theme.ts +197 -0
  79. package/src/index.ts +8 -0
  80. package/src/type_utils.ts +7 -0
  81. package/src/ui_dependency_provider.tsx +58 -0
  82. package/src/utils/copy_to_clipboard.ts +24 -0
  83. package/src/utils/image_color.ts +42 -0
  84. package/src/utils/index.ts +4 -0
  85. package/src/utils/resize_observer.ts +18 -0
  86. package/src/utils/sanitization.ts +14 -0
@@ -0,0 +1,136 @@
1
+ import type { FC } from 'react';
2
+ import { useMemo } from 'react';
3
+ import styled from 'styled-components';
4
+
5
+ import { ChevronLeftIcon, ChevronRightIcon } from '@apify/ui-icons';
6
+
7
+ import { theme } from '../../design_system/theme.js';
8
+ import { Box } from '../box.js';
9
+ import { Button } from '../button.js';
10
+
11
+ const LEADING_THREE_DOTS_PAGE_KEY = -1;
12
+ const TRAILING_THREE_DOTS_PAGE_KEY = -2;
13
+
14
+ const PaginationButtonBase = styled(Button).attrs({ variant: 'text' })`
15
+ padding: 0;
16
+ height: 28px;
17
+ min-width: 28px;
18
+ font-weight: 400 !important; /* default for button is medium, force regular to all page selection buttons */
19
+
20
+ &:disabled {
21
+ background: transparent;
22
+ }
23
+
24
+ &.currentPage {
25
+ background-color: ${theme.color.neutral.chipBackground};
26
+
27
+ &:hover {
28
+ background-color: ${theme.color.neutral.hover};
29
+ }
30
+ }
31
+ `;
32
+
33
+ const StyledPageSelectionButtons = styled(Box)`
34
+ display: inline-flex;
35
+ gap: ${theme.space.space8};
36
+ `;
37
+
38
+ export type PaginationButtonsProps = {
39
+ page: number;
40
+ totalPages: number;
41
+ onPageChange: (page: number) => void;
42
+ }
43
+
44
+ // TODO: Consolidate and move to /library
45
+ export const PaginationButtons: FC<PaginationButtonsProps> = ({
46
+ page,
47
+ totalPages,
48
+ onPageChange,
49
+ }) => {
50
+ // Pages to display buttons for (counting from 0, -1 and -2 will mean a special '...' disabled button)
51
+ const pagesToDisplay = useMemo(() => {
52
+ const result = [];
53
+ if (totalPages <= 8) {
54
+ for (let i = 0; i < totalPages; i++) {
55
+ result.push(i);
56
+ }
57
+ } else if (page < 5) {
58
+ for (let i = 0; i < 7; i++) {
59
+ result.push(i);
60
+ }
61
+ result.push(TRAILING_THREE_DOTS_PAGE_KEY);
62
+ } else if (page < totalPages - 4) {
63
+ result.push(0);
64
+ result.push(LEADING_THREE_DOTS_PAGE_KEY);
65
+ for (let i = page - 2; i <= page + 2; i++) {
66
+ result.push(i);
67
+ }
68
+ result.push(TRAILING_THREE_DOTS_PAGE_KEY);
69
+ } else {
70
+ result.push(0);
71
+ result.push(LEADING_THREE_DOTS_PAGE_KEY);
72
+ for (let i = totalPages - 6; i < totalPages; i++) {
73
+ result.push(i);
74
+ }
75
+ }
76
+ return result;
77
+ }, [page, totalPages]);
78
+
79
+ return (
80
+ <StyledPageSelectionButtons>
81
+ <PaginationButtonBase
82
+ data-test='page-prev-button'
83
+ disabled={page <= 0}
84
+ onClick={() => onPageChange(page - 1)}
85
+ trackingId='PaginationPrevPage'
86
+ >
87
+ <ChevronLeftIcon size="16" />
88
+ </PaginationButtonBase>
89
+ {pagesToDisplay.map((pageToDisplay) => {
90
+ if (pageToDisplay === LEADING_THREE_DOTS_PAGE_KEY || pageToDisplay === TRAILING_THREE_DOTS_PAGE_KEY) {
91
+ return (
92
+ <PaginationButtonBase
93
+ trackingId='ThreeDots'
94
+ key={pageToDisplay}
95
+ onClick={() => undefined}
96
+ disabled
97
+ >
98
+ ...
99
+ </PaginationButtonBase>
100
+ );
101
+ }
102
+ if (pageToDisplay === page) {
103
+ return (
104
+ <PaginationButtonBase
105
+ key={pageToDisplay}
106
+ data-test='current-page-button'
107
+ trackingId='PaginationCurrentPage'
108
+ className='currentPage'
109
+ onClick={() => undefined}
110
+ >
111
+ {pageToDisplay + 1}
112
+ </PaginationButtonBase>
113
+ );
114
+ }
115
+ return (
116
+ <PaginationButtonBase
117
+ key={pageToDisplay}
118
+ data-test='page-number-button'
119
+ onClick={() => onPageChange(pageToDisplay)}
120
+ trackingId='PaginationNumberedPage'
121
+ >
122
+ {pageToDisplay + 1}
123
+ </PaginationButtonBase>
124
+ );
125
+ })}
126
+ <PaginationButtonBase
127
+ data-test='page-next-button'
128
+ disabled={page >= totalPages - 1}
129
+ onClick={() => onPageChange(page + 1)}
130
+ trackingId='PaginationNextPage'
131
+ >
132
+ <ChevronRightIcon size="16" />
133
+ </PaginationButtonBase>
134
+ </StyledPageSelectionButtons>
135
+ );
136
+ };
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ import { theme } from '../../design_system/theme.js';
5
+ import { Text } from '../text/index.js';
6
+
7
+ const StyledChip = styled(Text)`
8
+ color: ${theme.color.neutral.text};
9
+ background-color: ${theme.color.neutral.chipBackground};
10
+ line-height: 1;
11
+ padding: ${theme.space.space2} ${theme.space.space4};
12
+ border-radius: ${theme.radius.radius8};
13
+
14
+ ._disabled & {
15
+ background-color: ${theme.color.neutral.backgroundSubtle};
16
+ color: ${theme.color.neutral.textDisabled};
17
+ }
18
+ `;
19
+
20
+ interface ChipProps {
21
+ children: React.ReactNode;
22
+ }
23
+
24
+ export const TabNumberChip: React.FC<ChipProps> = ({ children, ...rest }) => {
25
+ return <StyledChip
26
+ size='small'
27
+ {...rest}
28
+ >
29
+ {children}
30
+ </StyledChip>;
31
+ };
@@ -0,0 +1,183 @@
1
+ import StyleDictionary from 'style-dictionary';
2
+
3
+ const DO_NOT_EXPORT_COMMENT = `/**
4
+ * Do not edit directly, this file was auto-generated.
5
+ */
6
+ `;
7
+
8
+ function toCamelCase(str) {
9
+ return str
10
+ .toLowerCase()
11
+ .replace(/[^a-zA-Z0-9]+(.)/g, (_, chr) => chr.toUpperCase());
12
+ }
13
+
14
+ /**
15
+ * Converts an object to a TypeScript literal representation with proper indentation
16
+ * that can be written to a TypeScript file.
17
+ */
18
+ function objectToTSLiteral(obj, indentLevel = 0) {
19
+ const indent = (level) => ' '.repeat(level); // 2-space indent
20
+
21
+ if (obj && typeof obj === 'object') {
22
+ const entries = Object.entries(obj);
23
+ if (entries.length === 0) return '{}';
24
+ return `{\n${entries
25
+ .map(
26
+ ([key, value]) => `${indent(indentLevel + 1)}${key}: ${objectToTSLiteral(value, indentLevel + 1)}`,
27
+ )
28
+ .join('\n')}\n${indent(indentLevel)}}${indentLevel > 0 ? ',' : ''}`;
29
+ } if (typeof obj === 'string') {
30
+ return `'${obj}',`;
31
+ }
32
+ return String(obj);
33
+ }
34
+
35
+ /**
36
+ * Build color tokens for a given theme.
37
+ * @param theme {string} - The theme to build tokens, 'light' or 'dark'.
38
+ */
39
+ async function buildTheme(theme) {
40
+ // Transform to replace 'semantic' and 'decorative' with 'color' in token names
41
+ // Example: 'semantic-neutral-text' becomes 'color-neutral-text'
42
+ StyleDictionary.registerTransform({
43
+ name: 'name/prefix-color-name',
44
+ type: 'name',
45
+ transform: (prop) => {
46
+ return prop.name
47
+ .replace(/^semantic/, 'color')
48
+ .replace(/^decorative/, 'color');
49
+ },
50
+ });
51
+
52
+ // Format to generate typescript file that exports CSS variables as a string
53
+ // Example: export const tokens = `--color-neutral-text: #000; --color-primary: #fff;`
54
+ StyleDictionary.registerFormat({
55
+ name: 'typescript/css-variables-string',
56
+ format: ({ dictionary, options }) => {
57
+ const lines = dictionary.allTokens.map((token) => ` --${token.name}: ${token.$value};`);
58
+ return `${DO_NOT_EXPORT_COMMENT}\nexport const ${options.varName ?? 'tokens'} = \`\n${lines.join('\n')}\n\`;\n`;
59
+ },
60
+ });
61
+
62
+ // Format to generate typescript file that exports CSS properties as an object
63
+ // Example: export const tokens = { colorNeutralText: 'var(--color-neutral-text)', colorPrimary: 'var(--color-primary)' };
64
+ StyleDictionary.registerFormat({
65
+ name: 'typescript/css-color-properties',
66
+ format: ({ dictionary, options }) => {
67
+ const properties = {};
68
+ dictionary.allTokens.forEach((token) => {
69
+ const path = token.path.slice(1).map(toCamelCase);
70
+ let current = properties;
71
+ for (let i = 0; i < path.length - 1; i++) {
72
+ const key = path[i];
73
+ if (!(key in current)) {
74
+ current[key] = {};
75
+ }
76
+ current = current[key];
77
+ }
78
+ current[path[path.length - 1]] = `var(--${token.name})`;
79
+ });
80
+
81
+ return `${DO_NOT_EXPORT_COMMENT}\nexport const ${options.varName ?? 'tokens'} = ${objectToTSLiteral(properties)} as const;\n`;
82
+ },
83
+ });
84
+
85
+ // Format to generate typescript file that exports CSS colors as an object
86
+ // Example: export const tokens = { colorNeutralText: '#000', colorPrimary: '#fff' };
87
+ StyleDictionary.registerFormat({
88
+ name: 'typescript/css-color-values',
89
+ format: ({ dictionary, options }) => {
90
+ const properties = {};
91
+ dictionary.allTokens.forEach((token) => {
92
+ const path = token.path.slice(1);
93
+ const name = toCamelCase(path.join(' '));
94
+ properties[name] = token.$value;
95
+ });
96
+
97
+ return `${DO_NOT_EXPORT_COMMENT}\nexport const ${options.varName ?? 'tokens'} = ${objectToTSLiteral(properties)} as const;\n`;
98
+ },
99
+ });
100
+
101
+ // Select only tokens for semantic and decorative colors
102
+ StyleDictionary.registerFilter({
103
+ name: 'only-colors',
104
+ filter: (token) => ['Semantic', 'Decorative'].includes(token.path[0]),
105
+ });
106
+
107
+ // Select only tokens for palette colors
108
+ StyleDictionary.registerFilter({
109
+ name: 'only-palette',
110
+ filter: (token) => ['Palette'].includes(token.path[0]),
111
+ });
112
+
113
+ // Select only tokens for theme colors (Decorative and Palette)
114
+ StyleDictionary.registerFilter({
115
+ name: 'only-theme',
116
+ filter: (token) => ['Decorative', 'Palette'].includes(token.path[0]),
117
+ });
118
+
119
+ const sd = await (new StyleDictionary()).extend({
120
+ source: [`src/design_system/colors/figma_color_tokens.${theme}.json`],
121
+ platforms: {
122
+ ts: {
123
+ transformGroup: 'scss',
124
+ transforms: ['name/prefix-color-name'],
125
+ buildPath: 'src/design_system/colors/generated/',
126
+ files: [
127
+ {
128
+ destination: `css_variables.${theme}.ts`,
129
+ format: 'typescript/css-variables-string',
130
+ filter: 'only-colors',
131
+ },
132
+ {
133
+ destination: `css_variables_palette.${theme}.ts`,
134
+ format: 'typescript/css-variables-string',
135
+ filter: 'only-palette',
136
+ },
137
+ {
138
+ destination: `properties_theme.ts`,
139
+ format: 'typescript/css-color-properties',
140
+ filter: 'only-colors',
141
+ options: {
142
+ varName: 'colorProperties',
143
+ },
144
+ },
145
+ {
146
+ destination: `colors_theme.${theme}.ts`,
147
+ format: 'typescript/css-color-values',
148
+ filter: 'only-theme',
149
+ options: {
150
+ varName: `${theme}Theme`,
151
+ },
152
+ },
153
+ ],
154
+ },
155
+ style: {
156
+ transformGroup: 'scss',
157
+ transforms: ['name/prefix-color-name'],
158
+ buildPath: 'style/colors/',
159
+ files: [
160
+ {
161
+ destination: `${theme}.scss`,
162
+ format: 'scss/map-flat',
163
+ mapName: 'tokens',
164
+ filter: 'only-colors',
165
+ },
166
+ {
167
+ destination: `palette.${theme}.scss`,
168
+ format: 'scss/map-flat',
169
+ mapName: 'tokens',
170
+ filter: 'only-palette',
171
+ },
172
+ ],
173
+ },
174
+ },
175
+ });
176
+ await sd.buildPlatform('ts');
177
+ await sd.buildPlatform('style');
178
+ }
179
+
180
+ await Promise.all([
181
+ buildTheme('light'),
182
+ buildTheme('dark'),
183
+ ]);