```
-Note that you can even skip this attribute `data-h-entity-fake-link-target` if your clickable-container contains only one link inside. The script has a fallback in that case and it will take first link in the tree if target data attribute wasn't added for the link.
+Note that you can even skip this attribute `data-h-entity-fake-link-target` for your link if your clickable-container contains only one link inside. The script has a fallback in that case and it will take first link in the tree if target data attribute wasn't added for the link.
In storybook you have to call this script for your story like this:
```
-import entityFakeLink from '@skilld/kaizen-core/helpers/entity-fake-link/h-entity-fake-link';
-
-export const basic = (args = {}) => {
- ...
- useEffect(() => {
- entityFakeLink();
- }, [args]);
- ...
-};
+useEffect(() => {
+ Drupal.behaviors.kaizen_core_h_entity_fake_link.attach();
+}, [args]);
```
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)
-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.
+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.
+
+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`.
### Focus visible helper
-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)
+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)
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.
diff --git a/packages/kaizen-core/_border-box.css b/packages/kaizen-core/_border-box.css
index fb6c81e..b398bde 100644
--- a/packages/kaizen-core/_border-box.css
+++ b/packages/kaizen-core/_border-box.css
@@ -1,10 +1,7 @@
/* https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/ */
-html {
- box-sizing: border-box;
-}
-
+html,
*,
*::before,
*::after {
- box-sizing: inherit;
+ box-sizing: border-box;
}
diff --git a/packages/kaizen-core/helpers/entity-fake-link/entity-fake-link.css b/packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.css
similarity index 100%
rename from packages/kaizen-core/helpers/entity-fake-link/entity-fake-link.css
rename to packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.css
diff --git a/packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.js b/packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.js
index ac3dc87..a404cf8 100644
--- a/packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.js
+++ b/packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.js
@@ -4,58 +4,98 @@
* link wrapper around whole entity.
*/
-const fakeLinkEvents = (el, e) => {
- if (e.type === 'click' || e.key === 'Enter') {
- const ref = e.target != null ? e.target : e.srcElement;
- if (ref && ref.tagName !== 'A') {
- window.open(el.getAttribute('data-href'), el.getAttribute('data-target'));
- }
- }
-};
+(({ behaviors }) => {
+ behaviors.kaizen_core_h_entity_fake_link = {
+ defaultEntry: () => {
+ return {
+ wrapperData: '[data-h-entity-fake-link-container]',
+ targetData: '[data-h-entity-fake-link-target]',
+ processingName: 'storybook-a-button',
+ };
+ },
+ customEntry: () => {
+ // If you need a custom entry (in case if for example in drupal
+ // you have other classnames than in components - you can create
+ // a new .js file in src/js folder, and put into it the following
+ // construction:
+ // (({ behaviors }) => {
+ // behaviors.kaizen_core_h_entity_fake_link.customEntry = () => {
+ // return [
+ // {
+ // ...your configuration,
+ // },
+ // ...etc
+ // ];
+ // };
+ // })(Drupal);
+ //
+ // Then, you have to attach compiled version of your newly created
+ // js file to drupal. Be sure you have attached it before original
+ // component's js file -> because only in this case component's
+ // js can catch your custom entry.
+ },
+ entries: () => {
+ let entries = [behaviors.kaizen_core_h_entity_fake_link.defaultEntry()];
+ if (behaviors.kaizen_core_h_entity_fake_link.customEntry()) {
+ entries.push(...behaviors.kaizen_core_h_entity_fake_link.customEntry());
+ }
+ return entries;
+ },
+ attach: (context) => {
+ behaviors.kaizen_core_h_entity_fake_link.entries().forEach((entry) => {
+ once(entry.processingName, `${entry.wrapperData}`, context).forEach(
+ (el) => {
+ // Multiple links inside of element you want to wrap is not expected
+ // with this script. So it searches only the first matched.
+ let link = el.querySelector(`a${entry.targetData}[href]`);
+ if (!link) {
+ // Fallback search. If targetData is not defined, then let's try
+ // to catch just first matched link.
+ link = el.querySelector('a[href]');
+ }
+ if (link) {
+ behaviors.kaizen_core_h_entity_fake_link.handler({ el, link });
+ }
+ },
+ );
+ });
+ },
+ handler: (obj) => {
+ const { el } = obj;
+ const { link } = obj;
+ el.setAttribute('data-h-entity-fake-link-built', '');
+ el.setAttribute('tabindex', '0');
+ el.setAttribute('role', 'link');
+ el.setAttribute('data-href', link.getAttribute('href'));
+ el.setAttribute(
+ 'aria-label',
+ link.hasAttribute('title')
+ ? link.getAttribute('title')
+ : link.textContent.replace(/\s+/g, ' ').trim(),
+ );
+ el.setAttribute(
+ 'data-target',
+ link.hasAttribute('target') ? link.getAttribute('target') : '_self',
+ );
+ Array.prototype.forEach.call(el.querySelectorAll('a'), (innerLink) => {
+ innerLink.setAttribute('tabindex', '-1');
+ });
-const fakeLinkProcessed = (el, link) => {
- el.setAttribute('data-h-entity-fake-link-built', '');
- el.setAttribute('tabindex', '0');
- el.setAttribute('role', 'link');
- el.setAttribute('data-href', link.getAttribute('href'));
- el.setAttribute(
- 'aria-label',
- link.hasAttribute('title') ? link.getAttribute('title') : link.textContent.replace(/\s+/g, ' ').trim(),
- );
- el.setAttribute(
- 'data-target',
- link.hasAttribute('target') ? link.getAttribute('target') : '_self',
- );
- Array.prototype.forEach.call(el.querySelectorAll('a'), (innerLink) => {
- innerLink.setAttribute('tabindex', '-1');
- });
+ el.addEventListener('click', (e) => {
+ behaviors.kaizen_core_h_entity_fake_link.fakeLinkEvents({ el, e });
+ });
- el.addEventListener('click', (e) => {
- fakeLinkEvents(el, e);
- });
-
- el.addEventListener('keydown', (e) => {
- fakeLinkEvents(el, e);
- });
-};
-
-export default ({
- wrapperData = '[data-h-entity-fake-link-container]',
- targetData = '[data-h-entity-fake-link-target]',
- processingName = 'h-entity-fake-link',
- context = document,
-} = {}) => {
- once(processingName, wrapperData, context).forEach((el) => {
- // Multiple links inside of element you want to wrap is not expected
- // with this script. So it searches only the first matched.
- let link = el.querySelector(`a${targetData}[href]`);
- if (!link) {
- // Fallback search. If targetData is not defined, then let's try
- // to catch just first matched link.
- link = el.querySelector('a[href]');
- }
- if (link) {
- fakeLinkProcessed(el, link);
- }
- });
-};
\ No newline at end of file
+ el.addEventListener('keydown', (e) => {
+ behaviors.kaizen_core_h_entity_fake_link.fakeLinkEvents({ el, e });
+ });
+ },
+ fakeLinkEvents: (obj) => {
+ if (obj.e.type === 'click' || obj.e.key === 'Enter') {
+ const ref = obj.e.target != null ? obj.e.target : obj.e.srcElement;
+ if (ref && ref.tagName !== 'A') {
+ window.open(obj.el.getAttribute('data-href'), obj.el.getAttribute('data-target'));
+ }
+ }
+ },
+ };
+})(Drupal);
diff --git a/packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.md b/packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.md
index 8bb144b..01fdea5 100644
--- a/packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.md
+++ b/packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.md
@@ -1,3 +1,3 @@
# Helper / Entity-fake-link
-This component helps to simulate link around element, which contains original link.
+This component helps to simulate link around element, based on some original link.
diff --git a/packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.stories.js b/packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.stories.js
index c54c0db..ffbeb64 100644
--- a/packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.stories.js
+++ b/packages/kaizen-core/helpers/entity-fake-link/h-entity-fake-link.stories.js
@@ -1 +1,2 @@
-import './entity-fake-link.css';
+import './h-entity-fake-link.css';
+import './h-entity-fake-link';
diff --git a/packages/kaizen-core/helpers/focus-visible/focus-visible.css b/packages/kaizen-core/helpers/focus-visible/h-focus-visible.css
similarity index 100%
rename from packages/kaizen-core/helpers/focus-visible/focus-visible.css
rename to packages/kaizen-core/helpers/focus-visible/h-focus-visible.css
diff --git a/packages/kaizen-core/helpers/focus-visible/h-focus-visible.js b/packages/kaizen-core/helpers/focus-visible/h-focus-visible.js
index e479417..8620ffd 100644
--- a/packages/kaizen-core/helpers/focus-visible/h-focus-visible.js
+++ b/packages/kaizen-core/helpers/focus-visible/h-focus-visible.js
@@ -1,6 +1,6 @@
/**
* @file
- * This is Javascript slider functionality.
+ * This is Javascript focus-visible functionality.
*/
import 'focus-visible';
diff --git a/packages/kaizen-core/helpers/focus-visible/h-focus-visible.stories.js b/packages/kaizen-core/helpers/focus-visible/h-focus-visible.stories.js
index 36a6fa1..ae1f0a1 100644
--- a/packages/kaizen-core/helpers/focus-visible/h-focus-visible.stories.js
+++ b/packages/kaizen-core/helpers/focus-visible/h-focus-visible.stories.js
@@ -1,2 +1,2 @@
-import './focus-visible.css';
+import './h-focus-visible.css';
import './h-focus-visible';
diff --git a/packages/kaizen-core/helpers/root-variables/h-root-variables.js b/packages/kaizen-core/helpers/root-variables/h-root-variables.js
index 23d6262..ab0e29c 100644
--- a/packages/kaizen-core/helpers/root-variables/h-root-variables.js
+++ b/packages/kaizen-core/helpers/root-variables/h-root-variables.js
@@ -14,12 +14,20 @@ const hRootVariablesHandler = () => {
);
};
-const body = once('h-root-variables', document.documentElement).shift();
-if (body) {
- hRootVariablesHandler();
- ['load', 'resize'].forEach(event => {
- window.addEventListener(event, () => {
- hRootVariablesHandler();
- });
- })
-}
+(({ behaviors }) => {
+ behaviors.kaizen_core_h_root_variables = {
+ attach: (context) => {
+ const body = once(
+ 'h-root-variables',
+ document.documentElement,
+ context,
+ ).unshift();
+ if (body) {
+ hRootVariablesHandler();
+ ['DOMContentLoaded', 'load', 'resize'].forEach((event) =>
+ window.addEventListener(event, () => hRootVariablesHandler()),
+ );
+ }
+ },
+ };
+})(Drupal);
diff --git a/packages/kaizen-core/helpers/root-variables/h-root-variables.stories.js b/packages/kaizen-core/helpers/root-variables/h-root-variables.stories.js
index 8cce6dd..375cce3 100644
--- a/packages/kaizen-core/helpers/root-variables/h-root-variables.stories.js
+++ b/packages/kaizen-core/helpers/root-variables/h-root-variables.stories.js
@@ -1 +1,2 @@
import './h-root-variables';
+Drupal.behaviors.kaizen_core_h_root_variables.attach();
diff --git a/packages/kaizen-tg/README.md b/packages/kaizen-tg/README.md
index fd24c5b..5dcd11d 100644
--- a/packages/kaizen-tg/README.md
+++ b/packages/kaizen-tg/README.md
@@ -9,17 +9,13 @@
## Requirements
-- Docker-ce
-
-Or
-
- Node.js
- Yarn
## Features
-- PostCss
+- Postcss
- Storybook
- Webpack
- Browsersync
@@ -34,10 +30,13 @@ Or
## Usage
1. `cd web/themes/custom`
-2. `npx @skilld/kaizen-tg` and follow instructions. Or alternative installation using Docker `docker run -it --rm -u $(id -u):$(id -g) -v "$PWD":/app -w /app node:lts-alpine npx @skilld/kaizen-tg`
+2. `npx @skilld/kaizen-tg`
3. `cd [theme_name]`
-4. `yarn && yarn build` or `make install && make build` if you want to use docker instead of local
+4. `yarn install`
+
+## Compilation
+Run `yarn build` from theme dir
## Components creation
@@ -45,7 +44,7 @@ Run `yarn cc` from theme dir
## Storybook
-Run `yarn storybook` from theme dir to init storybook
+Run `yarn storybook` from theme dir
## Linting and fixing
diff --git a/packages/kaizen-tg/_templates/drupal-9-theme/new/.eslintignore b/packages/kaizen-tg/_templates/drupal-9-theme/new/.eslintignore
index 950f6c9..2200005 100644
--- a/packages/kaizen-tg/_templates/drupal-9-theme/new/.eslintignore
+++ b/packages/kaizen-tg/_templates/drupal-9-theme/new/.eslintignore
@@ -1,8 +1,7 @@
---
to: <%= h.src() %>/<%= h.changeCase.lower(name) %>/.eslintignore
---
-/dist/js/*.js
-/dist/storybook/
+/dist/**/*.js
/color/*.js
postcss.config.js
*.stories.js
diff --git a/packages/kaizen-tg/_templates/drupal-9-theme/new/.gitignore.t b/packages/kaizen-tg/_templates/drupal-9-theme/new/.gitignore.t
index f748c6b..f82d027 100644
--- a/packages/kaizen-tg/_templates/drupal-9-theme/new/.gitignore.t
+++ b/packages/kaizen-tg/_templates/drupal-9-theme/new/.gitignore.t
@@ -4,3 +4,4 @@ to: <%= h.src() %>/<%= h.changeCase.lower(name) %>/.gitignore
dist
node_modules
yarn-error.log
+storybook-static
diff --git a/packages/kaizen-tg/_templates/drupal-9-theme/new/.storybook/preview-head.html b/packages/kaizen-tg/_templates/drupal-9-theme/new/.storybook/preview-head.html
index 3a2633a..26714bc 100644
--- a/packages/kaizen-tg/_templates/drupal-9-theme/new/.storybook/preview-head.html
+++ b/packages/kaizen-tg/_templates/drupal-9-theme/new/.storybook/preview-head.html
@@ -4,3 +4,4 @@
+
diff --git a/packages/kaizen-tg/_templates/drupal-9-theme/new/.storybook/preview.js b/packages/kaizen-tg/_templates/drupal-9-theme/new/.storybook/preview.js
index d4788ba..e5b86d8 100644
--- a/packages/kaizen-tg/_templates/drupal-9-theme/new/.storybook/preview.js
+++ b/packages/kaizen-tg/_templates/drupal-9-theme/new/.storybook/preview.js
@@ -8,8 +8,8 @@ import config from '../<%= h.changeCase.lower(name) %>.breakpoints.yml';
window.themeBreakpoints = config;
// Import sprite.
-import svgSpritePath from '../dist/svg/sprite.svg';
-window.svgSpritePath = svgSpritePath;
+import svgSpritePath from '../dist/assets/sprite.svg';
+window.<%= h.changeCase.lower(name) %>SvgSpritePath = svgSpritePath;
// Extend Twig.js with drupal filters.
import Twig from 'twig';
@@ -17,3 +17,36 @@ import twigDrupalFilters from 'twig-drupal-filters';
import once from '@drupal/once';
window.once = once;
twigDrupalFilters(Twig);
+
+window.Drupal = { behaviors: {} };
+
+((Drupal, drupalSettings) => {
+ // Simplified Drupal.t() function just to be able to use such constructions
+ // directly from component's js behaviors.
+ Drupal.t = function (str) {
+ return str;
+ };
+
+ Drupal.throwError = function (error) {
+ setTimeout(function () {
+ throw error;
+ }, 0);
+ };
+
+ Drupal.attachBehaviors = function (context, settings) {
+ context = context || document;
+ settings = settings || drupalSettings;
+ const behaviors = Drupal.behaviors;
+ // Execute all of them.
+ Object.keys(behaviors || {}).forEach((i) => {
+ if (typeof behaviors[i].attach === 'function') {
+ // Don't stop the execution of behaviors in case of an error.
+ try {
+ behaviors[i].attach(context, settings);
+ } catch (e) {
+ Drupal.throwError(e);
+ }
+ }
+ });
+ };
+})(Drupal, window.drupalSettings);
diff --git a/packages/kaizen-tg/_templates/drupal-9-theme/new/.stylelintignore b/packages/kaizen-tg/_templates/drupal-9-theme/new/.stylelintignore
index d2ccd0c..694710c 100644
--- a/packages/kaizen-tg/_templates/drupal-9-theme/new/.stylelintignore
+++ b/packages/kaizen-tg/_templates/drupal-9-theme/new/.stylelintignore
@@ -2,3 +2,4 @@
to: <%= h.src() %>/<%= h.changeCase.lower(name) %>/.stylelintignore
---
/color/*.css
+/dist/**/*.css
diff --git a/packages/kaizen-tg/_templates/drupal-9-theme/new/Makefile b/packages/kaizen-tg/_templates/drupal-9-theme/new/Makefile
deleted file mode 100644
index 39fa2d9..0000000
--- a/packages/kaizen-tg/_templates/drupal-9-theme/new/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
----
-to: <%= h.src() %>/<%= h.changeCase.lower(name) %>/Makefile
----
-IMAGE_FRONT = node:lts-alpine
-
-# Execute front container function.
-front = docker run \
- --rm \
- --init \
- -v $(shell pwd):/usr/src/app -w /usr/src/app \
- -w /usr/src/app \
- $(IMAGE_FRONT) ${1}
-
-# Build front tasks.
-install:
- @echo "Installing dependencies..."
- $(call front, yarn install --ignore-optional --prod)
-
-build:
- $(call front, yarn build --verbose)
-
-lint:
- $(call front, yarn lint-fix)
-
diff --git a/packages/kaizen-tg/_templates/drupal-9-theme/new/README.md.t b/packages/kaizen-tg/_templates/drupal-9-theme/new/README.md.t
new file mode 100644
index 0000000..5d30999
--- /dev/null
+++ b/packages/kaizen-tg/_templates/drupal-9-theme/new/README.md.t
@@ -0,0 +1,53 @@
+---
+to: <%= h.src() %>/<%= h.changeCase.lower(name) %>/README.md
+---
+# <%= h.changeCase.sentenceCase(name) %>
+
+This theme was generated using [kaizen-tg](https://www.npmjs.com/package/@skilld/kaizen-tg) package.
+
+## Requirements
+
+- Node.js
+- Yarn
+
+
+## Features
+
+- Postcss
+- Storybook
+- Webpack
+- Browsersync
+- eslint
+- stylelint
+- Autoprefixer
+- Drupal Color Module support
+- Drupal breakpoints.yml config parser in css/js
+- Svg sprite generation
+- Several basic helpers which improves quality and perception of the web-sites. [Read more](https://www.npmjs.com/package/@skilld/kaizen-core)
+
+# Usage
+
+### Compilation
+
+Run `yarn build` from theme dir or `yarn build-dev` for development mode
+
+### Components creation
+
+Run `yarn cc` from theme dir
+
+### Storybook
+
+Run `yarn storybook` from theme dir
+
+### Linting and fixing
+
+Run `yarn lint-fix` from theme dir
+
+## Documentation about other related kaizen's packages.
+1. [kaizen-cg](https://www.npmjs.com/package/@skilld/kaizen-cg)
+2. [kaizen-core](https://www.npmjs.com/package/@skilld/kaizen-core)
+3. [kaizen-breakpoints](https://www.npmjs.com/package/@skilld/kaizen-breakpoints)
+
+# License
+
+This project is licensed under the MIT open source license.
diff --git a/packages/kaizen-tg/_templates/drupal-9-theme/new/assets/fonts/README.txt.t b/packages/kaizen-tg/_templates/drupal-9-theme/new/assets/fonts/README.txt.t
new file mode 100644
index 0000000..88008d0
--- /dev/null
+++ b/packages/kaizen-tg/_templates/drupal-9-theme/new/assets/fonts/README.txt.t
@@ -0,0 +1,4 @@
+---
+to: <%= h.src() %>/<%= h.changeCase.lower(name) %>/assets/fonts/README.txt
+---
+Place your fonts here.
diff --git a/packages/kaizen-tg/_templates/drupal-9-theme/new/images/svg/test.svg.t b/packages/kaizen-tg/_templates/drupal-9-theme/new/assets/images/svg/test.svg.t
similarity index 93%
rename from packages/kaizen-tg/_templates/drupal-9-theme/new/images/svg/test.svg.t
rename to packages/kaizen-tg/_templates/drupal-9-theme/new/assets/images/svg/test.svg.t
index 4c3a5f6..e418b61 100644
--- a/packages/kaizen-tg/_templates/drupal-9-theme/new/images/svg/test.svg.t
+++ b/packages/kaizen-tg/_templates/drupal-9-theme/new/assets/images/svg/test.svg.t
@@ -1,5 +1,5 @@
---
-to: <%= h.src() %>/<%= h.changeCase.lower(name) %>/images/svg/test.svg
+to: <%= h.src() %>/<%= h.changeCase.lower(name) %>/assets/images/svg/test.svg
---