Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"build:src:copy": "cp README.md NOTICE LICENSE lib/components/",
"build:src:docs": "node scripts/docs.js",
"build:src:environment": "node scripts/environment",
"build:themeable": "node scripts/themeable-source",
"build:themeable": "tsc -p tsconfig.src-themeable.json && node scripts/themeable-source.js",
"build:pages:vite": "vite build",
"build:pages:tsc": "tsc -p pages/tsconfig.json"
},
Expand Down
6 changes: 6 additions & 0 deletions scripts/package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ function themablePackage() {
version: pkg.version,
repository: pkg.repository,
homepage: pkg.homepage,
exports: {
".": {
types: "./theming.d.ts",
import: "./theming.js",
},
},
});
}
12 changes: 12 additions & 0 deletions scripts/themeable-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ function copyStyles() {
function copyTemplate() {
fs.mkdirSync(componentsTargetDir, { recursive: true });
fs.cpSync(componentsSourceDir, componentsTargetDir, { recursive: true });
fs.writeFileSync(
path.join(componentsTargetDir, "package.json"),
JSON.stringify(
{
name: "@cloudscape-design/chat-components-themed",
version: "1.0.0",
},
null,
2,
),
"utf-8",
);
}

copyTemplate();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// SPDX-License-Identifier: Apache-2.0
import { GlobalValue, ThemePreset, TypedModeValueOverride } from "@cloudscape-design/theming-build";

export interface TypedOverride {
tokens: Partial<Record<string, GlobalValue | TypedModeValueOverride>>;
}
export const preset: ThemePreset;
33 changes: 33 additions & 0 deletions src-themeable/theming.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { join } from "node:path";

import { buildThemedComponents as themingCoreBuild } from "@cloudscape-design/theming-build";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// eslint-disable-next-line import/no-useless-path-segments
import { preset, TypedOverride } from "./internal/template/internal/generated/theming/index.cjs";

const internalDir = join(__dirname, "./internal");
const scssDir = join(internalDir, "./scss");
const templateDir = join(internalDir, "./template");
const designTokensTemplateDir = join(internalDir, "./template-tokens");

export type Theme = TypedOverride;
export interface BuildThemedComponentsParams {
theme: Theme;
outputDir: string;
baseThemeId?: string;
}

export function buildThemedComponents({ theme, outputDir, baseThemeId }: BuildThemedComponentsParams): Promise<void> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to consider an option to allow overriding the specific component imports so this can use the themed components as its peer dependency.

return themingCoreBuild({
override: theme,
preset,
baseThemeId,
componentsOutputDir: join(outputDir, "components"),
designTokensOutputDir: join(outputDir, "design-tokens"),
templateDir,
designTokensTemplateDir,
scssDir,
});
}
17 changes: 17 additions & 0 deletions tsconfig.src-themeable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"lib": ["es2019", "dom", "dom.iterable"],
"target": "ES2019",
"module": "ESNext",
"moduleResolution": "nodenext",
"rootDir": "src-themeable",
"declaration": true,
"incremental": true,
"outDir": "lib/components-themeable",
"skipLibCheck": true,
"strict": true,
"tsBuildInfoFile": "./.cache/themeable-source.tsbuildinfo"
},
"include": ["src-themeable"],
"exclude": ["**/__tests__/**", "src/test-utils/**"]
}
Loading