Skip to content

feat: add @tutorialkit/theme package to use the theme without astro #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 28, 2024
Merged
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
5 changes: 2 additions & 3 deletions docs/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
"@iconify-json/svg-spinners": "^1.1.2",
"@tutorialkit/astro": "workspace:*",
"@tutorialkit/types": "workspace:*",
"@unocss/reset": "^0.60.4",
"@unocss/transformer-directives": "^0.60.4",
"@unocss/reset": "^0.59.4",
"astro": "^4.10.3",
"fast-glob": "^3.3.2",
"prettier-plugin-astro": "^0.14.0",
"typescript": "^5.4.5",
"unocss": "^0.60.4"
"unocss": "^0.59.4"
}
}
22 changes: 3 additions & 19 deletions docs/demo/uno.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { theme } from '@tutorialkit/astro';
import transformerDirectives from '@unocss/transformer-directives';
import { unoCSSConfig } from '@tutorialkit/astro';
import { globSync, convertPathToPattern } from 'fast-glob';
import fs from 'node:fs/promises';
import { basename, dirname, join } from 'node:path';
import { defineConfig, presetIcons, presetUno } from 'unocss';
import { defineConfig, presetIcons, presetUno, transformerDirectives } from 'unocss';

const iconPaths = globSync('./icons/languages/*.svg');

Expand All @@ -21,29 +20,14 @@ const customIconCollection = iconPaths.reduce(
);

export default defineConfig({
theme,
...unoCSSConfig,
content: {
inline: globSync(
`${convertPathToPattern(join(require.resolve('@tutorialkit/components-react'), '..'))}/**/*.js`,
).map((filePath) => {
return () => fs.readFile(filePath, { encoding: 'utf8' });
}),
},
rules: [
['scrollbar-transparent', { 'scrollbar-color': '#0000004d transparent' }],
['nav-box-shadow', { 'box-shadow': '0 2px 4px -1px rgba(0, 0, 0, 0.1)' }],
['transition-background', { 'transition-property': 'background' }],
],
shortcuts: {
'panel-container': 'grid grid-rows-[min-content_1fr] h-full',
'panel-header':
'flex items-center px-4 py-2 bg-tk-elements-panel-header-backgroundColor min-h-[38px] overflow-x-hidden',
'panel-tabs-header': 'flex bg-tk-elements-panel-header-backgroundColor h-[38px]',
'panel-title': 'flex items-center gap-1.5 text-tk-elements-panel-header-textColor',
'panel-icon': 'text-tk-elements-panel-header-iconColor',
'panel-button':
'flex items-center gap-1.5 whitespace-nowrap rounded-md text-sm bg-tk-elements-panel-headerButton-backgroundColor hover:bg-tk-elements-panel-headerButton-backgroundColorHover text-tk-elements-panel-headerButton-textColor hover:text-tk-elements-panel-headerButton-textColorHover',
},
transformers: [transformerDirectives()],
presets: [
presetUno({
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@tutorialkit/astro",
"version": "0.0.1-alpha.23",
"description": "TutorialKit integration for Astro (https://astro.build)",
"author": "StackBlitz Inc.",
"type": "module",
"bugs": "https://github.com/stackblitz/tutorialkit/issues",
"homepage": "https://github.com/stackblitz/tutorialkit",
Expand All @@ -28,6 +29,7 @@
"@nanostores/react": "0.7.2",
"@tutorialkit/components-react": "workspace:*",
"@tutorialkit/runtime": "workspace:*",
"@tutorialkit/theme": "workspace:*",
"@tutorialkit/types": "workspace:*",
"@types/react": "^18.3.3",
"@webcontainer/api": "1.2.0",
Expand Down
11 changes: 8 additions & 3 deletions packages/astro/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { rules, shortcuts, theme } from '@tutorialkit/theme';
import type { AstroConfig, AstroIntegration } from 'astro';
import { fileURLToPath } from 'node:url';
import { extraIntegrations } from './integrations.js';
import { updateMarkdownConfig } from './remark/index.js';
import { WebContainerFiles } from './webcontainer-files/index.js';
import { tutorialkitCore } from './vite-plugins/core.js';
import { userlandCSS, watchUserlandCSS } from './vite-plugins/css.js';
import { tutorialkitStore } from './vite-plugins/store.js';
import { tutorialkitCore } from './vite-plugins/core.js';
import { WebContainerFiles } from './webcontainer-files/index.js';

export { theme } from './theme.js';
export const unoCSSConfig = {
theme,
rules,
shortcuts,
};

export interface Options {
/**
Expand Down
7 changes: 6 additions & 1 deletion packages/astro/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
"outDir": "dist"
},
"include": ["src"],
"references": [{ "path": "../runtime" }, { "path": "../types" }, { "path": "../components/react" }]
"references": [
{ "path": "../runtime" },
{ "path": "../types" },
{ "path": "../components/react" },
{ "path": "../theme" }
]
}
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "tutorialkit",
"version": "0.0.1-alpha.23",
"description": "Interactive tutorials powered by WebContainer API",
"author": "StackBlitz Inc.",
"type": "module",
"bugs": "https://github.com/stackblitz/tutorialkit/issues",
"homepage": "https://github.com/stackblitz/tutorialkit",
Expand Down
1 change: 1 addition & 0 deletions packages/components/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@tutorialkit/components-react",
"version": "0.0.1-alpha.23",
"description": "TutorialKit's React components",
"author": "StackBlitz Inc.",
"type": "module",
"bugs": "https://github.com/stackblitz/tutorialkit/issues",
"homepage": "https://github.com/stackblitz/tutorialkit",
Expand Down
1 change: 1 addition & 0 deletions packages/create-tutorial/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "create-tutorial",
"version": "0.0.1-alpha.23",
"description": "Interactive tutorials powered by WebContainer API",
"author": "StackBlitz Inc.",
"type": "module",
"bugs": "https://github.com/stackblitz/tutorialkit/issues",
"homepage": "https://github.com/stackblitz/tutorialkit",
Expand Down
1 change: 1 addition & 0 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@tutorialkit/runtime",
"version": "0.0.1-alpha.23",
"description": "TutorialKit runtime",
"author": "StackBlitz Inc.",
"type": "module",
"bugs": "https://github.com/stackblitz/tutorialkit/issues",
"homepage": "https://github.com/stackblitz/tutorialkit",
Expand Down
1 change: 0 additions & 1 deletion packages/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@types/node": "^20.14.6",
"@types/react": "^18.3.3",
"@unocss/reset": "^0.59.4",
"@unocss/transformer-directives": "^0.59.4",
"astro": "4.10.3",
"fast-glob": "^3.3.2",
"prettier-plugin-astro": "^0.13.0",
Expand Down
22 changes: 3 additions & 19 deletions packages/template/uno.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { theme } from '@tutorialkit/astro';
import transformerDirectives from '@unocss/transformer-directives';
import { unoCSSConfig } from '@tutorialkit/astro';
import { globSync, convertPathToPattern } from 'fast-glob';
import fs from 'node:fs/promises';
import { basename, dirname, join } from 'node:path';
import { defineConfig, presetIcons, presetUno } from 'unocss';
import { defineConfig, presetIcons, presetUno, transformerDirectives } from 'unocss';

const iconPaths = globSync('./icons/languages/*.svg');

Expand All @@ -21,29 +20,14 @@ const customIconCollection = iconPaths.reduce(
);

export default defineConfig({
theme,
...unoCSSConfig,
content: {
inline: globSync(
`${convertPathToPattern(join(require.resolve('@tutorialkit/components-react'), '..'))}/**/*.js`,
).map((filePath) => {
return () => fs.readFile(filePath, { encoding: 'utf8' });
}),
},
rules: [
['scrollbar-transparent', { 'scrollbar-color': '#0000004d transparent' }],
['nav-box-shadow', { 'box-shadow': '0 2px 4px -1px rgba(0, 0, 0, 0.1)' }],
['transition-background', { 'transition-property': 'background' }],
],
shortcuts: {
'panel-container': 'grid grid-rows-[min-content_1fr] h-full',
'panel-header':
'flex items-center px-4 py-2 bg-tk-elements-panel-header-backgroundColor min-h-[38px] overflow-x-hidden',
'panel-tabs-header': 'flex bg-tk-elements-panel-header-backgroundColor h-[38px]',
'panel-title': 'flex items-center gap-1.5 text-tk-elements-panel-header-textColor',
'panel-icon': 'text-tk-elements-panel-header-iconColor',
'panel-button':
'flex items-center gap-1.5 whitespace-nowrap rounded-md text-sm bg-tk-elements-panel-headerButton-backgroundColor hover:bg-tk-elements-panel-headerButton-backgroundColorHover text-tk-elements-panel-headerButton-textColor hover:text-tk-elements-panel-headerButton-textColorHover',
},
transformers: [transformerDirectives()],
presets: [
presetUno({
Expand Down
26 changes: 26 additions & 0 deletions packages/theme/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@tutorialkit/theme",
"version": "0.0.1-alpha.23",
"description": "TutorialKit theme configuration",
"author": "StackBlitz Inc.",
"type": "module",
"bugs": "https://github.com/stackblitz/tutorialkit/issues",
"homepage": "https://github.com/stackblitz/tutorialkit",
"license": "MIT",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"files": [
"dist"
],
"scripts": {
"build": "tsc -b"
},
"dependencies": {
"unocss": "^0.59.4"
},
"devDependencies": {
"typescript": "^5.4.5"
}
}
20 changes: 20 additions & 0 deletions packages/theme/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { ConfigBase } from 'unocss';

export { theme } from './theme.js';

export const rules: ConfigBase['rules'] = [
['scrollbar-transparent', { 'scrollbar-color': '#0000004d transparent' }],
['nav-box-shadow', { 'box-shadow': '0 2px 4px -1px rgba(0, 0, 0, 0.1)' }],
['transition-background', { 'transition-property': 'background' }],
];

export const shortcuts: ConfigBase['shortcuts'] = {
'panel-container': 'grid grid-rows-[min-content_1fr] h-full',
'panel-header':
'flex items-center px-4 py-2 bg-tk-elements-panel-header-backgroundColor min-h-[38px] overflow-x-hidden',
'panel-tabs-header': 'flex bg-tk-elements-panel-header-backgroundColor h-[38px]',
'panel-title': 'flex items-center gap-1.5 text-tk-elements-panel-header-textColor',
'panel-icon': 'text-tk-elements-panel-header-iconColor',
'panel-button':
'flex items-center gap-1.5 whitespace-nowrap rounded-md text-sm bg-tk-elements-panel-headerButton-backgroundColor hover:bg-tk-elements-panel-headerButton-backgroundColorHover text-tk-elements-panel-headerButton-textColor hover:text-tk-elements-panel-headerButton-textColorHover',
};
4 changes: 2 additions & 2 deletions packages/astro/src/theme.ts → packages/theme/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const PRIMITIVES = {
},
};

export const theme: ConfigBase['theme'] = {
export const theme = {
colors: {
...PRIMITIVES,
tk: {
Expand Down Expand Up @@ -322,4 +322,4 @@ export const theme: ConfigBase['theme'] = {
},
},
},
};
} satisfies ConfigBase['theme'];
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm using a satisfies here so that they can import the theme and then override values and have autocompletion.

9 changes: 9 additions & 0 deletions packages/theme/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"composite": true
},
"include": ["src"]
}
1 change: 1 addition & 0 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@tutorialkit/types",
"version": "0.0.1-alpha.23",
"description": "Types for TutorialKit",
"author": "StackBlitz Inc.",
"type": "module",
"bugs": "https://github.com/stackblitz/tutorialkit/issues",
"homepage": "https://github.com/stackblitz/tutorialkit",
Expand Down
Loading