Skip to content

Commit

Permalink
Merge pull request #1381 from undp/develop
Browse files Browse the repository at this point in the history
Release 1.3.0
  • Loading branch information
Jura authored Sep 25, 2024
2 parents 22828b1 + 9a31a4b commit b5eeaf3
Show file tree
Hide file tree
Showing 257 changed files with 35,323 additions and 30,234 deletions.
7 changes: 6 additions & 1 deletion .babelrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
"loose": true
}
],
"@babel/preset-typescript"
[
"@babel/preset-typescript",
{
"runtime": "automatic"
}
]
],
"plugins": [
"@babel/plugin-transform-shorthand-properties",
Expand Down
33 changes: 25 additions & 8 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,33 @@ jobs:
# Operating System
runs-on: ubuntu-latest
# Job steps
# steps:
# - uses: actions/checkout@v1
# - name: Install dependencies
# # 👇 Install dependencies with the same package manager used in the project (replace it as needed), e.g. yarn, npm, pnpm
# run: yarn
# # 👇 Adds Chromatic as a step in the workflow
# - name: Publish to Chromatic
# uses: chromaui/action@v1
# # Chromatic GitHub Action options
# with:
# # 👇 Chromatic projectToken, refer to the manage page to obtain it.
# projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
# exitOnceUploaded: true
steps:
- uses: actions/checkout@v1
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
# 👇 Install dependencies with the same package manager used in the project (replace it as needed), e.g. yarn, npm, pnpm
run: yarn
# 👇 Adds Chromatic as a step in the workflow
- name: Publish to Chromatic
uses: chromaui/action@v1
# Chromatic GitHub Action options
# ⚠️ See your package manager's documentation for the correct command to install dependencies in a CI environment.
run: npm ci
- name: Run Chromatic
uses: chromaui/action@latest
with:
# 👇 Chromatic projectToken, refer to the manage page to obtain it.
# ⚠️ Make sure to configure a `CHROMATIC_PROJECT_TOKEN` repository secret
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
exitOnceUploaded: true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ yarn-error.log
.scannerwork
.vscode/
/.yarn
build-storybook.log
chromatic.log
chromatic-build-*.xml
chromatic-diagnostics.json
76 changes: 37 additions & 39 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,55 @@
const path = require("path");
module.exports = {
const path = require('path');

export default {
staticDirs: ['../stories/assets'],
stories: [
"../stories/**/*.stories.mdx"
],
stories: ['../stories/**/*.stories.@(js|jsx|ts|tsx)', '../stories/**/*.mdx'],
addons: [
"@storybook/addon-links",
"@storybook/addon-actions",
"@storybook/addon-docs",
"@storybook/addon-essentials",
"@whitespace/storybook-addon-html",
"storybook-addon-rtl",
"@storybook/addon-a11y"
'@storybook/addon-links',
{
name: '@storybook/addon-essentials',
options: {
actions: false, // 👈 disable the actions addon
},
},
'storybook-addon-rtl',
'@storybook/blocks',
'@storybook/addon-a11y',
'@storybook/react-webpack5',
// '@chromatic-com/storybook',
'@storybook/addon-webpack5-compiler-babel',
'@whitespace/storybook-addon-html'
],
features: {
storyStoreV7: true,
buildStoriesJson: true,
legacyMdx1: true,
babelModeV7: true
},
webpackFinal: async config => {
// remove hash from the static file names
// find the existing rule and override the name property
// config.module.rules.forEach(function(rule, index) {
// if (String(rule.test).search('svg') > 0) {
// if (typeof config.module.rules[index].options == 'undefined') {
// config.module.rules[index].options = {};
// }
// config.module.rules[index].options.name = 'static/media/[name].[ext]';
// }
// });
config.resolve.alias = {
...config.resolve.alias,
icons: path.resolve(__dirname, "../stories/assets/icons")
icons: path.resolve(__dirname, '../stories/assets/icons')
};
// add SCSS support for CSS Modules

config.module.rules.push({
test: /\.scss$/,
exclude: /node_modules/,
use: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, '../')
});

config.module.rules.push({
test: /\.(js|jsx)$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', ['@babel/preset-react', { "runtime": "automatic" }]]
}
}
});

return config;
},
framework: {
name: "@storybook/react-webpack5",
name: '@storybook/react-webpack5',
options: {}
},
env: config => ({
...config,
CHROMATIC_VIEWPORTS: [375, 768, 1380, 1920]
}),
docs: {
autodocs: true
}
// env: config => ({
// ...config,
// CHROMATIC_VIEWPORTS: [375, 768, 1380, 1920]
// }),
docs: {},
};
2 changes: 1 addition & 1 deletion .storybook/manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addons } from '@storybook/addons';
import { addons } from '@storybook/manager-api';
import theme from './theme';

addons.setConfig({
Expand Down
7 changes: 7 additions & 0 deletions .storybook/modes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const allModes = {
small: { viewport: "small" },
medium: { viewport: "medium" },
large: { viewport: "large" },
xlarge: { viewport: "xlarge" },
hd: { viewport: "hd" },
};
81 changes: 35 additions & 46 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
import { initializeRTL } from 'storybook-addon-rtl';
import renderToHTML from './renderToHTML'
// import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
// import * as RTLAddon from 'storybook-addon-rtl';
import renderToHTML from './renderToHTML';
import { allModes } from './modes';


// include base styling globally
import '!style-loader!css-loader!sass-loader!../stories/assets/scss/base-minimal.scss';
import '!style-loader!css-loader!sass-loader!../docs/css/components/documentation.min.css';

// initialise RTL
initializeRTL();
// Log the contents of RTLAddon for debugging

// console.log(RTLAddon);

// if (RTLAddon && typeof RTLAddon.default === 'function') {
// RTLAddon.default(); // Use the default export if it is a function
// } else {
// console.error('RTL initialization method not found.');
// }

// Configure Storybook
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
// actions: { disable: true },
controls: {
matchers: {
color: /(background|color)$/i,
Expand All @@ -26,7 +35,14 @@ export const parameters = {
},
},
viewport: {
viewports: INITIAL_VIEWPORTS,
// viewports: INITIAL_VIEWPORTS,
viewports: {
small: { name: "Small", styles: { width: "375px", height: "812px" } },
medium: { name: "Medium", styles: { width: "768px", height: "900px" } },
large: { name: "Large", styles: { width: "1380px", height: "768px" } },
xlarge: { name: "XLarge", styles: { width: "1600px", height: "900px" } },
hd: { name: "HD", styles: { width: "1920px", height: "1080px" } },
},
},
docs: {
source: {
Expand All @@ -37,18 +53,24 @@ export const parameters = {
options: {
storySort: {
method: 'alphabetical',
order: ['Getting started',['Intro','How to use our design system?','Browser support'],'Foundation','Components', 'Patterns', 'Utilities','Templates' ],
order: ['Getting started', ['Intro', 'How to use our design system?', 'Browser support'], 'Foundation', 'Components', 'Patterns', 'Utilities', 'Templates'],
includeName: true
},
},
chromatic: {
modes: {
small: allModes["small"],
medium: allModes["medium"],
large: allModes["large"],
xlarge: allModes["xlarge"],
hd: allModes["hd"],
},
pauseAnimationAtEnd: true,
delay: 1500
},
}

/* Implementing locale for language switcher */
// Note: Languages added to items array need to be added to the getLangCode() function below.
export const globalTypes = {
locale: {
title: 'Locale',
Expand Down Expand Up @@ -84,42 +106,29 @@ export const globalTypes = {
}
};

/**
* Function to get current language code.
*
* @param {*} Story renders Stories in iFrame.
* @param {*} context Current context for Addons.
* @returns Current Language Code.
*/
const getLangCode = (Story, context) => {
let activeLang = context.globals.locale;

// trigger onload event
// UI has some animation element which trigger on load.
let delay = 10;
setTimeout(function() {
setTimeout(function () {
const evt = new Event('load');
window.dispatchEvent(evt);
}, delay);

// Set window object for iframe.
window.UNDP.langCode = (window.UNDP) ? activeLang : window.UNDP= { langCode : activeLang };
window.UNDP.langCode = (window.UNDP) ? activeLang : window.UNDP = { langCode: activeLang };

// Language Array to map language alpha code.
const langArr = {
'english' : 'en',
'english': 'en',
'arabic': 'ar',
'burmese': 'my',
'japanese': 'ja',
'ukrainian': 'uk'
};

// Check if language exists.
if (typeof langArr[activeLang] == 'undefined') {
activeLang = 'english';
}

// Set HTML lang attribute for iframe.
const htmlElem = document.querySelector('html');
htmlElem.setAttribute('lang', langArr[activeLang]);

Expand All @@ -129,16 +138,11 @@ const getLangCode = (Story, context) => {
}

const sbFrameReset = (Story, context) => {
// Get Storybook Iframe's body element.
const iframeBody = document.querySelector('body');
// Get Storybook sidebar items in an array.
const sidebarItem = parent.document.querySelectorAll('.sidebar-item');
// Add click event listner on each sidebar item.
sidebarItem.forEach(function (item, i) {
item.addEventListener('click', function (e) {
// Classes to remove.
const classNames = ['sdgmodal-open', 'color-blue'];
// Check if above classes exist in `body` element and remove them.
if (classNames.some(className => iframeBody.classList.contains(className))) {
iframeBody.classList.remove(...classNames);
}
Expand All @@ -150,21 +154,16 @@ const sbFrameReset = (Story, context) => {
}

const setDirection = (Story, options) => {
// Set default direction.
let direction = 'ltr';
// LTR-RTL Toggle button.
const input = parent.document.querySelector('[aria-controls="rtl-status"]');
// Callback function for LTR-RTL Toggle.
const checkRTL = (elem) => {
if (elem.checked) {
direction = 'rtl';
}
}
// Change direction on LTR-RTL Toggle.
if (input && input.checked) {
input.addEventListener('change', checkRTL(input), false);
}
// Set window object for iframe.
if (typeof window.UNDP === 'undefined') {
window.UNDP = {};
}
Expand All @@ -175,27 +174,17 @@ const setDirection = (Story, options) => {
)
}

/**
* Function to set a global "accent-COLOR" class to the body.
*
* @param {*} Story renders Stories in iFrame.
* @param {*} context Current context for Addons.
* @returns Story with accent color processed.
*/
const setAccentClass = (Story, context) => {
let accent = context.globals.accent;
const bodyElem = document.querySelector('body');

// Remove any prexisting accent-COLOR items so we can apply the most recent
// global selection.
bodyElem.classList.forEach((item) => {
if (item.startsWith('accent-')) {
bodyElem.classList.remove(item);
}
});

if (Boolean(accent)) {
// Set accent class on body tag (the most parent of parents).
bodyElem.classList.add(`accent-${accent}`);
}

Expand All @@ -204,5 +193,5 @@ const setAccentClass = (Story, context) => {
)
}

// Trigger callback in Storybook Addons.
export const decorators = [getLangCode, sbFrameReset, setDirection, setAccentClass];
export const tags = ['autodocs', 'autodocs'];
4 changes: 2 additions & 2 deletions .storybook/renderToHTML.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { renderToStaticMarkup } from 'react-dom/server'
import { decode } from 'html-entities'
import prettier from 'prettier'
import HTMLParser from 'prettier/parser-html'
import * as prettier from 'prettier'
import * as HTMLParser from 'prettier/parser-html'

export default (story) => {
let html = prettier.format(decode(renderToStaticMarkup(story)), {
Expand Down
6 changes: 6 additions & 0 deletions chromatic.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://www.chromatic.com/config-file.schema.json",
"projectId": "UNDP Design System",
"exitOnceUploaded": true,
"skip": "dependabot/**"
}
2 changes: 1 addition & 1 deletion docs/css/base-minimal-no-grid.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/css/base-minimal.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/css/components/country-card.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b5eeaf3

Please sign in to comment.