Skip to content

Commit 820f1ea

Browse files
committed
Updates
1 parent 104b322 commit 820f1ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+311
-212
lines changed

packages/kaizen-breakpoints/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
_/ _/ _/_/_/ _/ _/_/_/_/ _/_/_/ _/ _/
88

99

10-
## What is this?
10+
## What is it?
1111

12-
- This package contains some script which parses breakpoints from Drupal's themename/themename.breakpoints.yml and adds them into css and javascript.
12+
- The goal of this package is to re-use `themename.breakpoints.yml` for providing same breakpoints into css and js
1313

1414
## Usage
1515

packages/kaizen-cg/README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
_/ _/ _/_/_/ _/ _/_/_/_/ _/_/_/ _/ _/
88

99

10-
## What is this?
10+
## What is it?
1111

1212
- This is a component generator for [kaizen-tg](https://www.npmjs.com/package/@skilld/kaizen-tg)
1313

@@ -17,6 +17,13 @@ Once [kaizen-tg](https://www.npmjs.com/package/@skilld/kaizen-tg) is installed,
1717
1. `cd [themename_dir]`
1818
2. `yarn cc` and follow instructions
1919

20+
## Structure
21+
1. `*.js` to store javascript code related to the component
22+
2. `*.json` to store modifiers of the component, such as default content for example
23+
3. `*.css` to store css code related to the component
24+
4. `*.html.twig` for templating
25+
5. `*.stories.js` for storybook initiation
26+
2027
## Should know
2128
1. Every component's js uses Drupal.behaviors structure and it works in storybook same way as in Drupal.
2229

packages/kaizen-cg/_templates/component/new/component-data.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
to: <%= h.src() %>/packages/components/<%= h.changeCase.lower(h.inflection.pluralize(component_type)) %>/<%= h.changeCase.lower(h.inflection.dasherize(name)) %>/<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.json
2+
to: <%= h.src() %>/components/<%= h.changeCase.lower(h.inflection.pluralize(component_type)) %>/<%= h.changeCase.lower(h.inflection.dasherize(name)) %>/<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.json
33
---
44
{
55
"defaultContent": {
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,60 @@
11
---
2-
to: <%= h.src() %>/packages/components/<%= h.changeCase.lower(h.inflection.pluralize(component_type)) %>/<%= h.changeCase.lower(h.inflection.dasherize(name)) %>/<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.js
2+
to: <%= h.src() %>/components/<%= h.changeCase.lower(h.inflection.pluralize(component_type)) %>/<%= h.changeCase.lower(h.inflection.dasherize(name)) %>/<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.js
33
---
44
/**
55
* @file
66
* This is component script template.
77
*/
88
(({ behaviors }) => {
99
<% if (typeof themeName != 'undefined') { %>behaviors.<%= h.changeCase.snakeCase(themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %> = {<% } else { %>behaviors.<%= h.changeCase.snakeCase(h.themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %> = {<% } %>
10+
defaultEntry: () => {
11+
return {
12+
className: '<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>',
13+
processingName: 'storybook-<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>',
14+
};
15+
},
16+
customEntry: () => {
17+
// If you need a custom entry (in case if for example in drupal
18+
// you have other classnames than in components - you can create
19+
// a new .js file in src/js folder, and put into it the following
20+
// construction:
21+
// (({ behaviors }) => {
22+
// <% if (typeof themeName != 'undefined') { %>behaviors.<%= h.changeCase.snakeCase(themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.customEntry = () => {<% } else { %>behaviors.<%= h.changeCase.snakeCase(h.themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.customEntry = () => {<% } %>
23+
// return [
24+
// {
25+
// ...your configuration,
26+
// },
27+
// ...etc
28+
// ];
29+
// };
30+
// })(Drupal);
31+
//
32+
// Then, you have to attach compiled version of your newly created
33+
// js file to drupal. Be sure you have attached it before original
34+
// component's js file -> because only in this case component's
35+
// js can catch your custom entry.
36+
},
1037
entries: () => {
11-
return [
12-
{
13-
className: '<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>',
14-
processingName: 'storybook-<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>',
15-
},
16-
];
38+
let entries = [<% if (typeof themeName != 'undefined') { %>behaviors.<%= h.changeCase.snakeCase(themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.defaultEntry()<% } else { %>behaviors.<%= h.changeCase.snakeCase(h.themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.defaultEntry()<% } %>];
39+
if (<% if (typeof themeName != 'undefined') { %>behaviors.<%= h.changeCase.snakeCase(themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.customEntry()<% } else { %>behaviors.<%= h.changeCase.snakeCase(h.themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.customEntry()<% } %>) {
40+
entries.push(...<% if (typeof themeName != 'undefined') { %>behaviors.<%= h.changeCase.snakeCase(themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.customEntry()<% } else { %>behaviors.<%= h.changeCase.snakeCase(h.themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.customEntry()<% } %>);
41+
}
42+
return entries;
1743
},
1844
attach: (context) => {
19-
<% if (typeof themeName != 'undefined') { %>Drupal.behaviors.<%= h.changeCase.snakeCase(themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.entries().forEach((entry) => {<% } else { %>behaviors.<%= h.changeCase.snakeCase(h.themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.entries().forEach((entry) => {<% } %>
45+
<% if (typeof themeName != 'undefined') { %>behaviors.<%= h.changeCase.snakeCase(themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.entries().forEach((entry) => {<% } else { %>behaviors.<%= h.changeCase.snakeCase(h.themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.entries().forEach((entry) => {<% } %>
2046
once(
2147
entry.processingName,
2248
`.${entry.className}`,
2349
context,
2450
).forEach((el) => {
25-
<% if (typeof themeName != 'undefined') { %>Drupal.behaviors.<%= h.changeCase.snakeCase(themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.handler(el, entry);<% } else { %>Drupal.behaviors.<%= h.changeCase.snakeCase(h.themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.handler(el, entry);<% } %>
51+
<% if (typeof themeName != 'undefined') { %>behaviors.<%= h.changeCase.snakeCase(themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.handler({ el, entry });<% } else { %>behaviors.<%= h.changeCase.snakeCase(h.themeName) %>_storybook_<%= h.changeCase.lower(component_type).charAt(0) %>_<%= h.changeCase.snakeCase(h.inflection.dasherize(name)) %>.handler({ el, entry });<% } %>
2652
});
2753
});
2854
},
29-
handler: (el, entry) => {
55+
handler: (obj) => {
3056
// eslint-disable-next-line no-console
31-
console.log(el, entry);
57+
console.log(obj.el);
3258
},
3359
};
3460
})(Drupal);

packages/kaizen-cg/_templates/component/new/component-source.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
to: <%= h.src() %>/packages/components/<%= h.changeCase.lower(h.inflection.pluralize(component_type)) %>/<%= h.changeCase.lower(h.inflection.dasherize(name)) %>/<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.css
2+
to: <%= h.src() %>/components/<%= h.changeCase.lower(h.inflection.pluralize(component_type)) %>/<%= h.changeCase.lower(h.inflection.dasherize(name)) %>/<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.css
33
---
44
.<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %> {
55
display: inherit;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
to: <%= h.src() %>/packages/components/<%= h.changeCase.lower(h.inflection.pluralize(component_type)) %>/<%= h.changeCase.lower(h.inflection.dasherize(name)) %>/<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.html.twig
2+
to: <%= h.src() %>/components/<%= h.changeCase.lower(h.inflection.pluralize(component_type)) %>/<%= h.changeCase.lower(h.inflection.dasherize(name)) %>/<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.html.twig
33
---
4-
<div {{ attributes }}>
4+
<div {{ attributes.addClass('<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>') }}>
55
{{- defaultContent.content -}}
66
</div>

packages/kaizen-cg/_templates/component/new/component.stories.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
---
2-
to: <%= h.src() %>/packages/components/<%= h.changeCase.lower(h.inflection.pluralize(component_type)) %>/<%= h.changeCase.lower(h.inflection.dasherize(name)) %>/<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.stories.js
2+
to: <%= h.src() %>/components/<%= h.changeCase.lower(h.inflection.pluralize(component_type)) %>/<%= h.changeCase.lower(h.inflection.dasherize(name)) %>/<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.stories.js
33
---
44
import './<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.css';
55
import './<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.js';
66
import drupalAttribute from 'drupal-attribute';
77
import { useEffect } from '@storybook/client-api';
8-
98
const template = require('./<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.html.twig');
109
const data = require('./<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>.json');
1110

1211
export default {
13-
title: '<%= h.changeCase.lower(h.inflection.pluralize(component_type)) %>/<%= h.changeCase.lower(h.inflection.dasherize(name)) %>',
12+
title: '<%= h.changeCase.lower(h.inflection.pluralize(component_type)) %>/<%= h.changeCase.sentenceCase(name) %>',
1413
parameters: {
1514
// Uncomment next line if you need fullscreen mode
1615
// layout: 'fullscreen',
@@ -24,9 +23,8 @@ data.<%= h.changeCase.snakeCase(themeName) %>SvgSpritePath = window.<%= h.change
2423
<% } else { %>
2524
data.<%= h.changeCase.snakeCase(h.themeName) %>SvgSpritePath = window.<%= h.changeCase.snakeCase(h.themeName) %>SvgSpritePath;
2625
<% } %>
27-
export const basic = (args = {}) => {
26+
const basicRender = (args) => {
2827
const attributes = new drupalAttribute();
29-
attributes.addClass(['<%= h.changeCase.lower(component_type).charAt(0) %>-<%= h.changeCase.lower(h.inflection.dasherize(name)) %>']);
3028
if (args.attributes) {
3129
for (const [attrName, attrValue] of Object.entries(args.attributes)) {
3230
if (attrName === 'class') {
@@ -46,3 +44,7 @@ export const basic = (args = {}) => {
4644
}, [args]);
4745
return template(data)
4846
};
47+
48+
export const basic = (args = {}) => {
49+
return basicRender(args);
50+
};

packages/kaizen-core/README.md

+9-13
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
_/ _/ _/_/_/ _/ _/_/_/_/ _/_/_/ _/ _/
88

99

10-
## What is this?
10+
## What is it?
1111

1212
- This package contains several helper's components which we are using on every project usually. And also it contains several css files which attached globally to storybook and drupal by default.
13-
13+
- This package can not be used as standalone. It's only working as a part of [kaizen-tg](https://www.npmjs.com/package/@skilld/kaizen-tg) package.
1414
### Entity fake link helper
1515

1616
This component helps you to easily simulate link to some wrapper, based on link inside of this wrapper. For example sometimes you need a whole teaser clickable based on its title's link-field. This script requires two data attributes added to the wrapper and to the link itself.
@@ -26,23 +26,19 @@ Note that you can even skip this attribute `data-h-entity-fake-link-target` for
2626

2727
In storybook you have to call this script for your story like this:
2828
```
29-
import entityFakeLink from '@skilld/kaizen-core/helpers/entity-fake-link/h-entity-fake-link';
30-
31-
export const basic = (args = {}) => {
32-
...
33-
useEffect(() => {
34-
entityFakeLink();
35-
}, [args]);
36-
...
37-
};
29+
useEffect(() => {
30+
Drupal.behaviors.kaizen_core_h_entity_fake_link.attach();
31+
}, [args]);
3832
```
3933
Styles for this helper called globally for storybook, so you don't need to import them manually (but actually the styles of this component contains only `cursor: pointer;` for the wrapper)
4034

41-
In Drupal this helper is not added by default, so if you need it - you have to manually import this component in `src/` folder and call its js/css globally or using drupal's libraries.
35+
If you need to use this helper in drupal - just uncomment drupal's library `h-entity-fake-link` in themename.libraries.yml and it will automatically work.
36+
37+
If you need to specify your custom configuration for drupal's usage, please see how it can be done from `themename/src/js/components/h-entity-fake-link.js`.
4238

4339
### Focus visible helper
4440

45-
This script improves focus experience for the people who don't need a visual accessibility. For example a native browser's behavior when you clicking on the button - is to add a focus rings automatically around button, but what if user doesn't have a problems with health? Browser's native focus rings creates sometimes a lot of unnecessary noise and worsens perception of the site actually. So this helper component helps to show focus ring only to the people who really needs it (for example with that helper focus ring can be shown by pressing TAB key, but it will be hidden if interactive element was focused by using mouse's buttons)
41+
This script improves focus experience for the people who don't need a visual accessibility. For example a native browser's behavior when you clicking on the button - is to add a focus rings automatically around button, but what if user doesn't have disabilities? Browser's native focus rings creates sometimes a lot of unnecessary noise and worsens perception of the site actually. So this helper component helps to show focus ring only to the people who really needs it (for example with that helper focus ring can be shown by pressing TAB key, but it will be hidden if interactive element was focused by using mouse's buttons)
4642

4743
This helper component is included globally already in storybook, when you installing [@skilld/kaizen-tg](https://www.npmjs.com/package/@skilld/kaizen-tg) theme. And also this script is included globally in `src/` folder (so Drupal have this script loaded by default too). You don't need to do anything manually with it.
4844

packages/kaizen-core/_border-box.css

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
/* https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/ */
2-
html {
3-
box-sizing: border-box;
4-
}
5-
2+
html,
63
*,
74
*::before,
85
*::after {
9-
box-sizing: inherit;
6+
box-sizing: border-box;
107
}

0 commit comments

Comments
 (0)