@wise/art 0.0.0-experimental-b088eec → 0.0.0-experimental-e5fd55b
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wise/art",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-e5fd55b",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React library for art elements in UI",
|
|
6
6
|
"homepage": "https://github.com/transferwise/web-art#readme",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"storybook": "^10.2.10",
|
|
77
77
|
"typescript": "^5.9.3",
|
|
78
78
|
"vite": "^7.3.1",
|
|
79
|
-
"wise-atoms": "git+https://github.com/transferwise/wise-atoms.git#
|
|
79
|
+
"wise-atoms": "git+https://github.com/transferwise/wise-atoms.git#b37005afd0ab740f763dbf022728b9e2a3b56736",
|
|
80
80
|
"@storybook/addon-docs": "^10.2.10",
|
|
81
81
|
"@changesets/cli": "^2.29.8",
|
|
82
82
|
"@changesets/changelog-github": "0.5.2"
|
|
@@ -96,16 +96,18 @@
|
|
|
96
96
|
"setup": "pnpm install && pnpm build",
|
|
97
97
|
"load-3d-i10s": "rm -rf s3-bucket/illustrations3d/ && node ./scripts/load-3d-i10s.mjs && pnpm load-riv",
|
|
98
98
|
"load-riv": "copyfiles -u 1 assets/*.riv s3-bucket/illustrations3d/rive",
|
|
99
|
-
"load-i10s": "copyfiles -u 4 node_modules/wise-atoms/
|
|
99
|
+
"load-i10s": "copyfiles -u 4 node_modules/wise-atoms/illustrations/**/*.png temp",
|
|
100
100
|
"load-flags": "rm -rf s3-bucket/flags/* && pnpm load-country-flags && pnpm load-currency-flags && pnpm transform-flags && pnpm convert-flags-svg-to-png",
|
|
101
101
|
"load-country-flags": "copyfiles -u 4 node_modules/wise-atoms/assets/flags/*.svg s3-bucket/flags && node ./scripts/generate-country-flags.mjs",
|
|
102
102
|
"load-currency-flags": "copyfiles -u 4 node_modules/wise-atoms/assets/flags/_metadata.json s3-bucket/flags && node ./scripts/generate-currency-flags.mjs",
|
|
103
103
|
"transform-flags": "node ./scripts/transform-flags.mjs",
|
|
104
104
|
"convert-flags-svg-to-png": "node ./scripts/convert-flags-svg-to-png.mjs",
|
|
105
|
+
"convert-i10s-png-to-webp": "rm -rf s3-bucket/illustrations/ && copyfiles --f node_modules/wise-atoms/illustrations/**/*.png s3-bucket/illustrations && node ./scripts/convert-png-to-webp.mjs",
|
|
105
106
|
"generate-i10s-metadata": "node ./scripts/generate-i10s-metadata.mjs && eslint 'src/illustrations/metadata.ts' --fix",
|
|
106
107
|
"generate-flags-metadata": "node ./scripts/generate-flags-metadata.mjs && eslint 'src/flags/metadata.ts' --fix",
|
|
107
108
|
"bundle": "rm -rf dist && rollup --config --sourcemap && pnpm build-styles",
|
|
108
|
-
"
|
|
109
|
+
"cleanup": "rm -rf temp",
|
|
110
|
+
"build": "NODE_ENV=web-art-prod pnpm load-i10s && pnpm load-3d-i10s && pnpm convert-i10s-png-to-webp && pnpm generate-i10s-metadata && pnpm load-flags && pnpm generate-flags-metadata && pnpm bundle && pnpm cleanup",
|
|
109
111
|
"start": "storybook dev -p 3001",
|
|
110
112
|
"dev": "NODE_ENV=web-art-dev pnpm start",
|
|
111
113
|
"test": "jest",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
-
import flagRawMetaData from "../../node_modules/wise-atoms/assets/flags/_metadata.json";
|
|
3
2
|
|
|
3
|
+
import flagRawMetaData from '../../node_modules/wise-atoms/assets/flags/_metadata.json';
|
|
4
4
|
import { Flag } from './Flag';
|
|
5
5
|
|
|
6
6
|
const meta: Meta<typeof Flag> = {
|
|
@@ -11,25 +11,66 @@ export default meta;
|
|
|
11
11
|
|
|
12
12
|
type Story = StoryObj<typeof Flag>;
|
|
13
13
|
|
|
14
|
+
interface GroupedFlag { name: string; countryCode?: string; currencyCodes: string[] }
|
|
15
|
+
|
|
16
|
+
const toTitleCase = (str: string) =>
|
|
17
|
+
str.replace(/\b\w/gu, (char) => char.toUpperCase());
|
|
18
|
+
|
|
19
|
+
const deriveName = (slug: string): string => {
|
|
20
|
+
if (!slug.includes('-')) return toTitleCase(slug);
|
|
21
|
+
const nameSlug = slug.slice(slug.indexOf('-') + 1);
|
|
22
|
+
return toTitleCase(nameSlug.replace(/-/gu, ' '));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const groupByCountry = (
|
|
26
|
+
entries: [string, (typeof flagRawMetaData)[keyof typeof flagRawMetaData]][],
|
|
27
|
+
): GroupedFlag[] => {
|
|
28
|
+
const countryMap = new Map<string, GroupedFlag>();
|
|
29
|
+
const standaloneFlags: GroupedFlag[] = [];
|
|
30
|
+
|
|
31
|
+
for (const [slug, data] of entries) {
|
|
32
|
+
const isDetailed = 'detailed' in data && data.detailed;
|
|
33
|
+
if (!isDetailed) {
|
|
34
|
+
const iso2 = 'iso2' in data ? data.iso2 : undefined;
|
|
35
|
+
const currencyCode = 'currencyCode' in data ? data.currencyCode : undefined;
|
|
36
|
+
|
|
37
|
+
if (iso2) {
|
|
38
|
+
const existing = countryMap.get(iso2);
|
|
39
|
+
if (existing) {
|
|
40
|
+
if (currencyCode) existing.currencyCodes.push(currencyCode);
|
|
41
|
+
} else {
|
|
42
|
+
countryMap.set(iso2, {
|
|
43
|
+
name: deriveName(slug),
|
|
44
|
+
countryCode: iso2,
|
|
45
|
+
currencyCodes: currencyCode ? [currencyCode] : [],
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
standaloneFlags.push({
|
|
50
|
+
name: deriveName(slug),
|
|
51
|
+
currencyCodes: currencyCode ? [currencyCode] : [],
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return [...countryMap.values(), ...standaloneFlags];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const allEntries = Object.entries(flagRawMetaData);
|
|
61
|
+
const allFlagsSorted = groupByCountry(allEntries).sort((a, b) =>
|
|
62
|
+
a.name.localeCompare(b.name),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const getFlagsByRegion = (region: string): GroupedFlag[] =>
|
|
66
|
+
groupByCountry(allEntries.filter(([, data]) => data.group === region));
|
|
67
|
+
|
|
14
68
|
// Helper function to render all flags and sizes for a given region
|
|
15
|
-
const AllFlagsAndSizes = (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const name = key
|
|
21
|
-
.replace(/^[a-z0-9]+-/u, '')
|
|
22
|
-
.split('-')
|
|
23
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
24
|
-
.join(' ');
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
key,
|
|
28
|
-
name,
|
|
29
|
-
iso2: 'iso2' in entry ? entry.iso2 : undefined,
|
|
30
|
-
currencyCode: 'currencyCode' in entry ? entry.currencyCode : undefined,
|
|
31
|
-
};
|
|
32
|
-
});
|
|
69
|
+
const AllFlagsAndSizes = (
|
|
70
|
+
region: string,
|
|
71
|
+
flagsOverride?: GroupedFlag[],
|
|
72
|
+
) => {
|
|
73
|
+
const regionFlags = flagsOverride ?? getFlagsByRegion(region);
|
|
33
74
|
|
|
34
75
|
return (
|
|
35
76
|
<>
|
|
@@ -53,11 +94,11 @@ const AllFlagsAndSizes = (region: string) => {
|
|
|
53
94
|
}}
|
|
54
95
|
>
|
|
55
96
|
{regionFlags.map((flag) => {
|
|
56
|
-
const flagCode = flag.
|
|
97
|
+
const flagCode = flag.countryCode ?? flag.currencyCodes[0];
|
|
57
98
|
|
|
58
99
|
return (
|
|
59
100
|
<div
|
|
60
|
-
key={flag.
|
|
101
|
+
key={flag.name}
|
|
61
102
|
style={{
|
|
62
103
|
display: 'flex',
|
|
63
104
|
flexDirection: 'column',
|
|
@@ -87,17 +128,22 @@ const AllFlagsAndSizes = (region: string) => {
|
|
|
87
128
|
>
|
|
88
129
|
<strong>{flag.name}</strong>
|
|
89
130
|
<span>
|
|
90
|
-
{flag.
|
|
131
|
+
{flag.countryCode && (
|
|
91
132
|
<>
|
|
92
|
-
Country: <code>{flag.
|
|
93
|
-
</>
|
|
94
|
-
)}
|
|
95
|
-
{flag.currencyCode && (
|
|
96
|
-
<>
|
|
97
|
-
{flag.iso2 && <br />}
|
|
98
|
-
Currency: <code>{flag.currencyCode}</code>
|
|
133
|
+
Country: <code>{flag.countryCode}</code>
|
|
99
134
|
</>
|
|
100
135
|
)}
|
|
136
|
+
{flag.currencyCodes.length > 0 && (
|
|
137
|
+
<>
|
|
138
|
+
<br />
|
|
139
|
+
<span>
|
|
140
|
+
{`${flag.currencyCodes.length === 1 ? 'Currency' : 'Currencies'}: `}
|
|
141
|
+
{flag.currencyCodes.map((currencyCode) => (
|
|
142
|
+
<code key={currencyCode}>{currencyCode}</code>
|
|
143
|
+
))}
|
|
144
|
+
</span>
|
|
145
|
+
</>
|
|
146
|
+
)}
|
|
101
147
|
</span>
|
|
102
148
|
</div>
|
|
103
149
|
</div>
|
|
@@ -108,6 +154,14 @@ const AllFlagsAndSizes = (region: string) => {
|
|
|
108
154
|
);
|
|
109
155
|
};
|
|
110
156
|
|
|
157
|
+
// Stories for each region
|
|
158
|
+
export const World: Story = {
|
|
159
|
+
render: () => AllFlagsAndSizes('World', allFlagsSorted),
|
|
160
|
+
parameters: {
|
|
161
|
+
chromatic: { disableSnapshot: true },
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
|
|
111
165
|
export const Africa: Story = {
|
|
112
166
|
render: () => AllFlagsAndSizes('Africa'),
|
|
113
167
|
};
|
|
@@ -143,3 +197,7 @@ export const SouthAmerica: Story = {
|
|
|
143
197
|
export const Misc: Story = {
|
|
144
198
|
render: () => AllFlagsAndSizes('Misc'),
|
|
145
199
|
};
|
|
200
|
+
|
|
201
|
+
export const Fallback: Story = {
|
|
202
|
+
render: () => AllFlagsAndSizes('Fallback'),
|
|
203
|
+
};
|