Skip to content

Commit 606a07e

Browse files
committed
wip: sync design tokens
1 parent 04195fd commit 606a07e

File tree

9 files changed

+501
-28
lines changed

9 files changed

+501
-28
lines changed

package-lock.json

Lines changed: 371 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"build:src:environment": "node scripts/environment",
3636
"build:themeable": "node scripts/themeable-source",
3737
"build:pages:vite": "vite build",
38-
"build:pages:tsc": "tsc -p pages/tsconfig.json"
38+
"build:pages:tsc": "tsc -p pages/tsconfig.json",
39+
"postinstall": "node ./scripts/install-peer-dependency.js components:charts-design-tokens"
3940
},
4041
"exports": {
4142
".": "./index.js",

pages/app/app-context.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { createContext } from "react";
4+
import { createContext, useEffect } from "react";
55
import { useSearchParams } from "react-router-dom";
66
import mapValues from "lodash/mapValues";
77

@@ -49,22 +49,36 @@ function parseQuery(urlParams: URLSearchParams) {
4949
});
5050
}
5151

52+
function formatQuery(params: AppUrlParams) {
53+
const query: Record<string, string> = {};
54+
for (const [key, value] of Object.entries(params)) {
55+
if (value === appContextDefaults.urlParams[key as keyof AppUrlParams]) {
56+
continue;
57+
}
58+
query[key as keyof AppUrlParams] = String(value);
59+
}
60+
return query;
61+
}
62+
5263
export function AppContextProvider({ children }: { children: React.ReactNode }) {
5364
const [searchParams, setSearchParams] = useSearchParams();
5465
const urlParams = parseQuery(searchParams) as AppUrlParams;
5566

5667
function setUrlParams(newParams: Partial<AppUrlParams>) {
57-
if (newParams.mode !== urlParams.mode) {
58-
applyMode(newParams.mode ?? appContextDefaults.urlParams.mode, document.documentElement);
59-
}
60-
if (newParams.density !== urlParams.density) {
61-
applyDensity(newParams.density ?? appContextDefaults.urlParams.density, document.documentElement);
62-
}
63-
if (newParams.direction !== urlParams.direction) {
64-
document.documentElement.setAttribute("dir", newParams.direction ?? appContextDefaults.urlParams.direction);
65-
}
66-
setSearchParams({ ...searchParams, ...newParams });
68+
setSearchParams(formatQuery({ ...urlParams, ...newParams }));
6769
}
6870

71+
useEffect(() => {
72+
applyMode(urlParams.mode);
73+
}, [urlParams.mode]);
74+
75+
useEffect(() => {
76+
applyDensity(urlParams.density);
77+
}, [urlParams.density]);
78+
79+
useEffect(() => {
80+
document.documentElement.setAttribute("dir", urlParams.direction);
81+
}, [urlParams.direction]);
82+
6983
return <AppContext.Provider value={{ urlParams, setUrlParams: setUrlParams }}>{children}</AppContext.Provider>;
7084
}

pages/app/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ import AppContext, { AppContextProvider } from "./app-context";
1919

2020
import "@cloudscape-design/global-styles/index.css";
2121

22+
const awsuiVisualRefreshFlag = Symbol.for("awsui-visual-refresh-flag");
23+
window[awsuiVisualRefreshFlag] = () => true;
24+
25+
interface ExtendedWindow extends Window {
26+
[awsuiVisualRefreshFlag]?: () => boolean;
27+
}
28+
declare const window: ExtendedWindow;
29+
2230
export default function App() {
2331
return (
2432
<I18nProvider locale="en" messages={[enMessages]}>
@@ -50,10 +58,7 @@ function Navigation() {
5058
const isCompactMode = urlParams.density === Density.Compact;
5159
const isRtl = urlParams.direction === "rtl";
5260
return (
53-
<header
54-
id="h"
55-
style={{ position: "sticky", insetBlockStart: 0, insetInlineStart: 0, insetInlineEnd: 0, zIndex: 1002 }}
56-
>
61+
<header id="h" style={{ position: "sticky", insetBlockStart: 0, zIndex: 1002 }}>
5762
<TopNavigation
5863
identity={{
5964
title: "Chart components - dev pages",
@@ -98,6 +103,7 @@ function IndexPage() {
98103
const tree = createPagesTree(pages);
99104
return (
100105
<AppLayout
106+
headerSelector="#h"
101107
navigationHide={true}
102108
toolsHide={true}
103109
content={

pages/common/templates.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export function Page({
2222
const [toolsOpen, setToolsOpen] = useState(!!settings);
2323
return (
2424
<AppLayout
25+
headerSelector="#h"
2526
navigationHide={true}
2627
tools={settings && <Drawer header={<Header variant="h2">Page settings</Header>}>{settings}</Drawer>}
2728
toolsOpen={toolsOpen}

scripts/install-peer-dependency.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env node
2+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// Can be used in postinstall script like so:
6+
// "postinstall": "node ./scripts/install-peer-dependency.js collection-hooks:property-filter-token-groups"
7+
// where "collection-hooks" is the package to fetch and "property-filter-token-groups" is the branch name in GitHub.
8+
9+
import { execSync } from "child_process";
10+
import process from "node:process";
11+
import os from "os";
12+
import path from "path";
13+
14+
const getModules = (packageName) => {
15+
switch (packageName) {
16+
case "components":
17+
return ["components", "design-tokens"];
18+
default:
19+
return [packageName];
20+
}
21+
};
22+
23+
const getArtifactPath = (moduleName) => {
24+
switch (moduleName) {
25+
case "components":
26+
return "/lib/components/*";
27+
case "design-tokens":
28+
return "/lib/design-tokens/*";
29+
case '"board-components':
30+
return "/lib/components/*";
31+
default:
32+
return "/lib/*";
33+
}
34+
};
35+
36+
const args = process.argv.slice(2);
37+
if (args.length < 1) {
38+
console.error("Usage: install-peer-dependency.js <package-name>:<target-branch>");
39+
process.exit(1);
40+
}
41+
const [packageName, targetBranch] = args[0].split(":");
42+
const targetRepository = `https://github.com/cloudscape-design/${packageName}.git`;
43+
const nodeModulesPath = path.join(process.cwd(), "node_modules", "@cloudscape-design");
44+
const tempDir = path.join(os.tmpdir(), `temp-${packageName}`);
45+
46+
// Clone the repository and checkout the branch
47+
console.log(`Cloning ${packageName}:${targetBranch}...`);
48+
execCommand(`git clone ${targetRepository} ${tempDir}`);
49+
process.chdir(tempDir);
50+
execCommand(`git checkout ${targetBranch}`);
51+
52+
// Install dependencies and build
53+
console.log(`Installing dependencies and building ${packageName}...`);
54+
execCommand("npm install");
55+
execCommand("npm run build");
56+
57+
// Remove existing peer dependency in node_modules
58+
for (const moduleName of getModules(packageName)) {
59+
const modulePath = path.join(nodeModulesPath, moduleName);
60+
const artifactPath = getArtifactPath(moduleName);
61+
62+
console.log(`Removing existing ${moduleName} from node_modules...`, modulePath);
63+
execCommand(`rm -rf ${modulePath}`);
64+
65+
// Copy built peer dependency to node_modules
66+
console.log(`Copying built ${moduleName} to node_modules...`, modulePath, `${tempDir}${artifactPath}`);
67+
execCommand(`mkdir -p ${modulePath}`);
68+
execCommand(`cp -R ${tempDir}${artifactPath} ${modulePath}`);
69+
}
70+
71+
// Clean up
72+
console.log("Cleaning up...");
73+
execCommand(`rm -rf ${tempDir}`);
74+
75+
console.log(`${packageName} has been successfully installed from branch ${targetBranch}!`);
76+
77+
function execCommand(command, options = {}) {
78+
try {
79+
execSync(command, { stdio: "inherit", ...options });
80+
} catch (error) {
81+
console.error(`Error executing command: ${command}`);
82+
console.error(`Error message: ${error.message}`);
83+
console.error(`Stdout: ${error.stdout && error.stdout.toString()}`);
84+
console.error(`Stderr: ${error.stderr && error.stderr.toString()}`);
85+
throw error;
86+
}
87+
}

src/internal/components/chart-series-details/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ function ExpandableSeries({
162162
<ChartSeriesMarker type={markerType} status={markerStatus} color={color} />
163163
</div>
164164
)}
165-
{/* TODO: custom expandable section? */}
166165
<div className={styles["full-width"]}>
167166
<ExpandableSection
168167
headerText={itemKey}

src/internal/components/popover/arrow.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// Based on $awsui-box-shadow-inner shadow, but rotated based on x and y multipliers.
1919
@mixin awsui-box-shadow-inner-rotated($x, $y) {
2020
$box-shadow-size: 0.71px; // Box shadow is actually 1px, but rotating the arrow changes this to sqrt(1/2)
21-
box-shadow: ($box-shadow-size * $x) ($box-shadow-size * $y) 4px -2px rgba(0, 28, 36, 0.5); // TODO: use design token
21+
box-shadow: ($box-shadow-size * $x) ($box-shadow-size * $y) 4px -2px cs.$color-shadow-default;
2222
}
2323

2424
$arrow-edge-length: 14px;
@@ -65,7 +65,7 @@
6565

6666
&-outer {
6767
&::after {
68-
background-color: #545b64; // TODO: use design token
68+
background-color: cs.$color-border-popover;
6969
}
7070
}
7171

src/internal/components/popover/container.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
border-end-start-radius: cs.$border-radius-popover;
2323
border-end-end-radius: cs.$border-radius-popover;
2424
background-color: cs.$color-background-popover;
25-
box-shadow: 0px 4px 20px 1px rgba(0, 4, 12, 1); // TODO: use design token
26-
border-block: cs.$border-width-popover solid #545b64; // TODO: use design token
27-
border-inline: cs.$border-width-popover solid #545b64; // TODO: use design token
25+
box-shadow: cs.$shadow-popover;
26+
border-block: cs.$border-width-popover solid cs.$color-border-popover;
27+
border-inline: cs.$border-width-popover solid cs.$color-border-popover;
2828
}
2929

3030
.container-body-variant-annotation {

0 commit comments

Comments
 (0)