Skip to content

Commit

Permalink
refactor: replace theme-light with light-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Daydreamer-riri committed Jan 1, 2024
1 parent 59fefd7 commit a535543
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions color/_var.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Don't edit this file directly. It is generated by `material3-style color`. */

@mixin theme-light {
@mixin light-theme {
--md-sys-color-primary: #6f43c0;
--md-sys-color-on-primary: #ffffff;
--md-sys-color-primary-container: #ebddff;
Expand Down Expand Up @@ -61,7 +61,7 @@
--m3-color-inverse-primary: var(--md-sys-color-inverse-primary);
}

@mixin theme-dark {
@mixin dark-theme {
--md-sys-color-primary: #d3bbff;
--md-sys-color-on-primary: #3f008d;
--md-sys-color-primary-container: #5727a6;
Expand Down
5 changes: 5 additions & 0 deletions color/style/dark-theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@use '../var';

:root {
@include var.dark-theme();
}
5 changes: 5 additions & 0 deletions color/style/light-theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@use '../var';

:root {
@include var.light-theme();
}
5 changes: 0 additions & 5 deletions color/style/theme-dark.scss

This file was deleted.

5 changes: 0 additions & 5 deletions color/style/theme-light.scss

This file was deleted.

4 changes: 2 additions & 2 deletions example/color-demo/theme.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@use './node_modules/material3-style/color/var';

:root {
@include var.theme-light();
@include var.light-theme();
}

.dark:root {
@include var.theme-dark();
@include var.dark-theme();
}

body {
Expand Down
12 changes: 8 additions & 4 deletions src/colorGen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'node:path'
import fs from 'node:fs/promises'
import { existsSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import type { Scheme } from '@material/material-color-utilities'
import { argbFromHex, hexFromArgb, themeFromSourceColor } from '@material/material-color-utilities'
Expand All @@ -25,18 +26,21 @@ export async function generateTheme(input: string = '#673ab7', customColors?: st
const targetFile = path.resolve(__dirname, '../color/_var.scss')
const content = `/** Don't edit this file directly. It is generated by \`material3-style color\`. */
@mixin theme-light {
@mixin light-theme {
${lightVars}
}
@mixin theme-dark {
@mixin dark-theme {
${darkVars}
}
`
await fs.writeFile(targetFile, content, 'utf-8')

const cssLightFile = path.resolve(__dirname, '../color/css/theme-light.css')
const cssDarkFile = path.resolve(__dirname, '../color/css/theme-dark.css')
const cssLightFile = path.resolve(__dirname, '../color/css/light-theme.css')
const cssDarkFile = path.resolve(__dirname, '../color/css/dark-theme.css')
const cssDir = path.dirname(cssLightFile)
if (existsSync(cssDir))
await fs.mkdir(cssDir, { recursive: true })
await Promise.all([
fs.writeFile(cssLightFile, `:root {${lightVars.replaceAll(/[ \n]/g, '')}}`, 'utf-8'),
fs.writeFile(cssDarkFile, `:root {${lightVars.replaceAll(/[ \n]/g, '')}}`, 'utf-8'),
Expand Down

0 comments on commit a535543

Please sign in to comment.