@ethlete/components 1.0.0-next.46 → 1.0.0-next.47

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.
@@ -1,10 +1,32 @@
1
1
  import { names } from '@nx/devkit';
2
2
  const KEBAB = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
3
- export function componentNames(name) {
3
+ /** Every category under `Components/` in Storybook. A new domain has to join one of them. */
4
+ export const COMPONENT_CATEGORIES = [
5
+ 'Actions',
6
+ 'Data display',
7
+ 'Date & time',
8
+ 'Dev tools',
9
+ 'Feedback',
10
+ 'Forms',
11
+ 'Layout',
12
+ 'Media',
13
+ 'Navigation',
14
+ 'Overlays',
15
+ 'Sports',
16
+ ];
17
+ /** Mirrors Storybook's own title-to-id slugify, so `storyIdPrefix` matches the id it will really get. */
18
+ const slugify = (value) => value
19
+ .toLowerCase()
20
+ .replace(/[^a-z0-9]+/g, '-')
21
+ .replace(/^-+|-+$/g, '');
22
+ export function componentNames(name, category = 'Layout') {
4
23
  const { fileName, className, constantName } = names(name.trim());
5
24
  if (!KEBAB.test(fileName)) {
6
25
  throw new Error(`"${name}" is not a usable domain name. Use kebab-case, e.g. "stat-tile".`);
7
26
  }
27
+ if (!COMPONENT_CATEGORIES.includes(category)) {
28
+ throw new Error(`"${category}" is not a Storybook category. Use one of: ${COMPONENT_CATEGORIES.join(', ')}.`);
29
+ }
8
30
  const words = fileName.replace(/-/g, ' ');
9
31
  return {
10
32
  fileName,
@@ -13,7 +35,8 @@ export function componentNames(name) {
13
35
  elementSelector: `et-${fileName}`,
14
36
  attributeSelector: `et${className}`,
15
37
  title: words.charAt(0).toUpperCase() + words.slice(1),
16
- storyIdPrefix: `components-${fileName}`,
38
+ category,
39
+ storyIdPrefix: `components-${slugify(category)}-${fileName}`,
17
40
  };
18
41
  }
19
42
  //# sourceMappingURL=component-names.js.map
@@ -162,7 +162,7 @@ export function storiesFile(n) {
162
162
  import { ${n.className}StorybookComponent } from './${n.fileName}-storybook.component';
163
163
 
164
164
  export default {
165
- title: 'Components/${n.title}',
165
+ title: 'Components/${n.category}/${n.title}',
166
166
  component: ${n.className}StorybookComponent,
167
167
  decorators: [moduleMetadata({ imports: [${n.className}StorybookComponent] })],
168
168
  } as Meta<${n.className}StorybookComponent>;
@@ -17,7 +17,7 @@ export default async function generate(tree, schema) {
17
17
  }
18
18
  let names;
19
19
  try {
20
- names = componentNames(schema.name);
20
+ names = componentNames(schema.name, schema.category);
21
21
  }
22
22
  catch (error) {
23
23
  logger.error(`❌ ${error instanceof Error ? error.message : String(error)}`);
@@ -29,6 +29,41 @@
29
29
  ]
30
30
  }
31
31
  },
32
+ "category": {
33
+ "type": "string",
34
+ "description": "Storybook category the story sits under, below 'Components'. Also decides the story id prefix used by the docs page's <StoryEmbed>.",
35
+ "enum": [
36
+ "Actions",
37
+ "Data display",
38
+ "Date & time",
39
+ "Dev tools",
40
+ "Feedback",
41
+ "Forms",
42
+ "Layout",
43
+ "Media",
44
+ "Navigation",
45
+ "Overlays",
46
+ "Sports"
47
+ ],
48
+ "default": "Layout",
49
+ "x-prompt": {
50
+ "message": "Which Storybook category does the domain belong to?",
51
+ "type": "list",
52
+ "items": [
53
+ { "value": "Actions", "label": "Actions - buttons and the things you press" },
54
+ { "value": "Data display", "label": "Data display - showing values and records" },
55
+ { "value": "Date & time", "label": "Date & time - calendars, schedulers, pickers" },
56
+ { "value": "Dev tools", "label": "Dev tools - developer-facing panels" },
57
+ { "value": "Feedback", "label": "Feedback - status, loading, errors, tips" },
58
+ { "value": "Forms", "label": "Forms - controls that carry a value" },
59
+ { "value": "Layout", "label": "Layout - containers and arrangement" },
60
+ { "value": "Media", "label": "Media - images, video, carousels" },
61
+ { "value": "Navigation", "label": "Navigation - moving between places" },
62
+ { "value": "Overlays", "label": "Overlays - things that float above the page" },
63
+ { "value": "Sports", "label": "Sports - brackets, standings, matches" }
64
+ ]
65
+ }
66
+ },
32
67
  "project": {
33
68
  "type": "string",
34
69
  "description": "Nx project to scaffold into. The domain lands in its '<sourceRoot>/lib/<name>'.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethlete/components",
3
- "version": "1.0.0-next.46",
3
+ "version": "1.0.0-next.47",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {