Skip to content

Commit b5eeaf3

Browse files
authored
Merge pull request #1381 from undp/develop
Release 1.3.0
2 parents 22828b1 + 9a31a4b commit b5eeaf3

File tree

257 files changed

+35323
-30234
lines changed

Some content is hidden

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

257 files changed

+35323
-30234
lines changed

.babelrc.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
"loose": true
99
}
1010
],
11-
"@babel/preset-typescript"
11+
[
12+
"@babel/preset-typescript",
13+
{
14+
"runtime": "automatic"
15+
}
16+
]
1217
],
1318
"plugins": [
1419
"@babel/plugin-transform-shorthand-properties",

.github/workflows/chromatic.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,33 @@ jobs:
1212
# Operating System
1313
runs-on: ubuntu-latest
1414
# Job steps
15+
# steps:
16+
# - uses: actions/checkout@v1
17+
# - name: Install dependencies
18+
# # 👇 Install dependencies with the same package manager used in the project (replace it as needed), e.g. yarn, npm, pnpm
19+
# run: yarn
20+
# # 👇 Adds Chromatic as a step in the workflow
21+
# - name: Publish to Chromatic
22+
# uses: chromaui/action@v1
23+
# # Chromatic GitHub Action options
24+
# with:
25+
# # 👇 Chromatic projectToken, refer to the manage page to obtain it.
26+
# projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
27+
# exitOnceUploaded: true
1528
steps:
16-
- uses: actions/checkout@v1
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
- uses: actions/setup-node@v4
34+
with:
35+
node-version: 20
1736
- name: Install dependencies
18-
# 👇 Install dependencies with the same package manager used in the project (replace it as needed), e.g. yarn, npm, pnpm
19-
run: yarn
20-
# 👇 Adds Chromatic as a step in the workflow
21-
- name: Publish to Chromatic
22-
uses: chromaui/action@v1
23-
# Chromatic GitHub Action options
37+
# ⚠️ See your package manager's documentation for the correct command to install dependencies in a CI environment.
38+
run: npm ci
39+
- name: Run Chromatic
40+
uses: chromaui/action@latest
2441
with:
25-
# 👇 Chromatic projectToken, refer to the manage page to obtain it.
42+
# ⚠️ Make sure to configure a `CHROMATIC_PROJECT_TOKEN` repository secret
2643
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
2744
exitOnceUploaded: true

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ yarn-error.log
1111
.scannerwork
1212
.vscode/
1313
/.yarn
14+
build-storybook.log
15+
chromatic.log
16+
chromatic-build-*.xml
17+
chromatic-diagnostics.json

.storybook/main.js

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,55 @@
1-
const path = require("path");
2-
module.exports = {
1+
const path = require('path');
2+
3+
export default {
34
staticDirs: ['../stories/assets'],
4-
stories: [
5-
"../stories/**/*.stories.mdx"
6-
],
5+
stories: ['../stories/**/*.stories.@(js|jsx|ts|tsx)', '../stories/**/*.mdx'],
76
addons: [
8-
"@storybook/addon-links",
9-
"@storybook/addon-actions",
10-
"@storybook/addon-docs",
11-
"@storybook/addon-essentials",
12-
"@whitespace/storybook-addon-html",
13-
"storybook-addon-rtl",
14-
"@storybook/addon-a11y"
7+
'@storybook/addon-links',
8+
{
9+
name: '@storybook/addon-essentials',
10+
options: {
11+
actions: false, // 👈 disable the actions addon
12+
},
13+
},
14+
'storybook-addon-rtl',
15+
'@storybook/blocks',
16+
'@storybook/addon-a11y',
17+
'@storybook/react-webpack5',
18+
// '@chromatic-com/storybook',
19+
'@storybook/addon-webpack5-compiler-babel',
20+
'@whitespace/storybook-addon-html'
1521
],
16-
features: {
17-
storyStoreV7: true,
18-
buildStoriesJson: true,
19-
legacyMdx1: true,
20-
babelModeV7: true
21-
},
2222
webpackFinal: async config => {
23-
// remove hash from the static file names
24-
// find the existing rule and override the name property
25-
// config.module.rules.forEach(function(rule, index) {
26-
// if (String(rule.test).search('svg') > 0) {
27-
// if (typeof config.module.rules[index].options == 'undefined') {
28-
// config.module.rules[index].options = {};
29-
// }
30-
// config.module.rules[index].options.name = 'static/media/[name].[ext]';
31-
// }
32-
// });
3323
config.resolve.alias = {
3424
...config.resolve.alias,
35-
icons: path.resolve(__dirname, "../stories/assets/icons")
25+
icons: path.resolve(__dirname, '../stories/assets/icons')
3626
};
37-
// add SCSS support for CSS Modules
27+
3828
config.module.rules.push({
3929
test: /\.scss$/,
40-
exclude: /node_modules/,
4130
use: ['style-loader', 'css-loader', 'sass-loader'],
4231
include: path.resolve(__dirname, '../')
4332
});
33+
34+
config.module.rules.push({
35+
test: /\.(js|jsx)$/,
36+
use: {
37+
loader: 'babel-loader',
38+
options: {
39+
presets: ['@babel/preset-env', ['@babel/preset-react', { "runtime": "automatic" }]]
40+
}
41+
}
42+
});
43+
4444
return config;
4545
},
4646
framework: {
47-
name: "@storybook/react-webpack5",
47+
name: '@storybook/react-webpack5',
4848
options: {}
4949
},
50-
env: config => ({
51-
...config,
52-
CHROMATIC_VIEWPORTS: [375, 768, 1380, 1920]
53-
}),
54-
docs: {
55-
autodocs: true
56-
}
50+
// env: config => ({
51+
// ...config,
52+
// CHROMATIC_VIEWPORTS: [375, 768, 1380, 1920]
53+
// }),
54+
docs: {},
5755
};

.storybook/manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { addons } from '@storybook/addons';
1+
import { addons } from '@storybook/manager-api';
22
import theme from './theme';
33

44
addons.setConfig({

.storybook/modes.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const allModes = {
2+
small: { viewport: "small" },
3+
medium: { viewport: "medium" },
4+
large: { viewport: "large" },
5+
xlarge: { viewport: "xlarge" },
6+
hd: { viewport: "hd" },
7+
};

.storybook/preview.js

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
2-
import { initializeRTL } from 'storybook-addon-rtl';
3-
import renderToHTML from './renderToHTML'
1+
// import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
2+
// import * as RTLAddon from 'storybook-addon-rtl';
3+
import renderToHTML from './renderToHTML';
4+
import { allModes } from './modes';
5+
46

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

9-
// initialise RTL
10-
initializeRTL();
11+
// Log the contents of RTLAddon for debugging
12+
13+
// console.log(RTLAddon);
14+
15+
// if (RTLAddon && typeof RTLAddon.default === 'function') {
16+
// RTLAddon.default(); // Use the default export if it is a function
17+
// } else {
18+
// console.error('RTL initialization method not found.');
19+
// }
1120

1221
// Configure Storybook
1322
export const parameters = {
14-
actions: { argTypesRegex: "^on[A-Z].*" },
23+
// actions: { disable: true },
1524
controls: {
1625
matchers: {
1726
color: /(background|color)$/i,
@@ -26,7 +35,14 @@ export const parameters = {
2635
},
2736
},
2837
viewport: {
29-
viewports: INITIAL_VIEWPORTS,
38+
// viewports: INITIAL_VIEWPORTS,
39+
viewports: {
40+
small: { name: "Small", styles: { width: "375px", height: "812px" } },
41+
medium: { name: "Medium", styles: { width: "768px", height: "900px" } },
42+
large: { name: "Large", styles: { width: "1380px", height: "768px" } },
43+
xlarge: { name: "XLarge", styles: { width: "1600px", height: "900px" } },
44+
hd: { name: "HD", styles: { width: "1920px", height: "1080px" } },
45+
},
3046
},
3147
docs: {
3248
source: {
@@ -37,18 +53,24 @@ export const parameters = {
3753
options: {
3854
storySort: {
3955
method: 'alphabetical',
40-
order: ['Getting started',['Intro','How to use our design system?','Browser support'],'Foundation','Components', 'Patterns', 'Utilities','Templates' ],
56+
order: ['Getting started', ['Intro', 'How to use our design system?', 'Browser support'], 'Foundation', 'Components', 'Patterns', 'Utilities', 'Templates'],
4157
includeName: true
4258
},
4359
},
4460
chromatic: {
61+
modes: {
62+
small: allModes["small"],
63+
medium: allModes["medium"],
64+
large: allModes["large"],
65+
xlarge: allModes["xlarge"],
66+
hd: allModes["hd"],
67+
},
4568
pauseAnimationAtEnd: true,
4669
delay: 1500
4770
},
4871
}
4972

5073
/* Implementing locale for language switcher */
51-
// Note: Languages added to items array need to be added to the getLangCode() function below.
5274
export const globalTypes = {
5375
locale: {
5476
title: 'Locale',
@@ -84,42 +106,29 @@ export const globalTypes = {
84106
}
85107
};
86108

87-
/**
88-
* Function to get current language code.
89-
*
90-
* @param {*} Story renders Stories in iFrame.
91-
* @param {*} context Current context for Addons.
92-
* @returns Current Language Code.
93-
*/
94109
const getLangCode = (Story, context) => {
95110
let activeLang = context.globals.locale;
96111

97-
// trigger onload event
98-
// UI has some animation element which trigger on load.
99112
let delay = 10;
100-
setTimeout(function() {
113+
setTimeout(function () {
101114
const evt = new Event('load');
102115
window.dispatchEvent(evt);
103116
}, delay);
104117

105-
// Set window object for iframe.
106-
window.UNDP.langCode = (window.UNDP) ? activeLang : window.UNDP= { langCode : activeLang };
118+
window.UNDP.langCode = (window.UNDP) ? activeLang : window.UNDP = { langCode: activeLang };
107119

108-
// Language Array to map language alpha code.
109120
const langArr = {
110-
'english' : 'en',
121+
'english': 'en',
111122
'arabic': 'ar',
112123
'burmese': 'my',
113124
'japanese': 'ja',
114125
'ukrainian': 'uk'
115126
};
116127

117-
// Check if language exists.
118128
if (typeof langArr[activeLang] == 'undefined') {
119129
activeLang = 'english';
120130
}
121131

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

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

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

152156
const setDirection = (Story, options) => {
153-
// Set default direction.
154157
let direction = 'ltr';
155-
// LTR-RTL Toggle button.
156158
const input = parent.document.querySelector('[aria-controls="rtl-status"]');
157-
// Callback function for LTR-RTL Toggle.
158159
const checkRTL = (elem) => {
159160
if (elem.checked) {
160161
direction = 'rtl';
161162
}
162163
}
163-
// Change direction on LTR-RTL Toggle.
164164
if (input && input.checked) {
165165
input.addEventListener('change', checkRTL(input), false);
166166
}
167-
// Set window object for iframe.
168167
if (typeof window.UNDP === 'undefined') {
169168
window.UNDP = {};
170169
}
@@ -175,27 +174,17 @@ const setDirection = (Story, options) => {
175174
)
176175
}
177176

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

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

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

@@ -204,5 +193,5 @@ const setAccentClass = (Story, context) => {
204193
)
205194
}
206195

207-
// Trigger callback in Storybook Addons.
208196
export const decorators = [getLangCode, sbFrameReset, setDirection, setAccentClass];
197+
export const tags = ['autodocs', 'autodocs'];

.storybook/renderToHTML.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { renderToStaticMarkup } from 'react-dom/server'
22
import { decode } from 'html-entities'
3-
import prettier from 'prettier'
4-
import HTMLParser from 'prettier/parser-html'
3+
import * as prettier from 'prettier'
4+
import * as HTMLParser from 'prettier/parser-html'
55

66
export default (story) => {
77
let html = prettier.format(decode(renderToStaticMarkup(story)), {

chromatic.config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://www.chromatic.com/config-file.schema.json",
3+
"projectId": "UNDP Design System",
4+
"exitOnceUploaded": true,
5+
"skip": "dependabot/**"
6+
}

docs/css/base-minimal-no-grid.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/css/base-minimal.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/css/components/country-card.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)