-
Notifications
You must be signed in to change notification settings - Fork 77
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
fix: global css file reduce 5000 lines #7980
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3e7bcb0
fix(design-tokens): add tokens and normalize refs
alisonailea 45191ae
feat: add tokens to theme files
alisonailea 546f23e
fix(tabs): normalize token references
alisonailea 86806de
fix(token-transformer): handle compound tokens
alisonailea c9778a7
feat: refactor tokentransformer to reduce file size
alisonailea aa33ba3
feat: refactor tokens to reduce file size
alisonailea 2772014
feat: add mode publisher to manage component modes
alisonailea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
packages/calcite-components/src/components/accordion-item/accordion-item.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Default | ||
let modeStore: Mode = "light"; | ||
// TODO: is this the right local storage key name? | ||
export const storageKey = "calcite-theme"; | ||
export type Mode = "dark" | "light"; | ||
export type Disconnect = () => void; | ||
|
||
export type ModePublisher<T> = () => { | ||
(value: T): void; | ||
subscribe(listener: (msg: T) => void): () => boolean; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export const modePublisher = <T>() => { | ||
const listeners = new Set<(value: T) => void>(); | ||
function createPublisher(value: T) { | ||
for (const cb of listeners) { | ||
cb(value); | ||
} | ||
} | ||
createPublisher.subscribe = (listener: (msg: T) => void) => { | ||
listeners.add(listener); | ||
return () => listeners.delete(listener); | ||
}; | ||
return createPublisher; | ||
}; | ||
|
||
type GetMode<T> = { | ||
(): T; | ||
subscribe(cb: (arg: T) => void): Disconnect; | ||
}; | ||
|
||
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: light)").matches) { | ||
// is light | ||
modeStore = "light"; | ||
} else if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) { | ||
// is dark | ||
modeStore = "dark"; | ||
} | ||
|
||
let pub: ReturnType<ModePublisher<Mode>>; | ||
|
||
export const getMode: GetMode<Mode> = () => (localStorage.getItem(storageKey) as Mode) ?? modeStore; | ||
|
||
getMode.subscribe = (cb: (arg: Mode) => void) => { | ||
pub = pub ?? modePublisher<Mode>(); | ||
return pub.subscribe(cb); | ||
}; | ||
|
||
export const setMode = (mode: Mode): void => { | ||
localStorage.setItem(storageKey, mode); | ||
pub && pub(mode); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { readdirSync } from "fs"; | ||
import { readdir } from "fs/promises"; | ||
import { resolve, dirname } from "path"; | ||
import { fileURLToPath } from "url"; | ||
import { Config, File } from "../support/run"; | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
const modesDirectory = resolve(__dirname, "calcite"); | ||
const componentsDirectory = resolve(__dirname, "component"); | ||
const globalSourceReference = [resolve(__dirname, "core.json"), resolve(__dirname, "semantic.json")]; | ||
|
||
const { components, componentRefs } = await readdir(componentsDirectory, { withFileTypes: true }).then((components) => | ||
components.reduce( | ||
(acc, c) => { | ||
if (c.isDirectory()) { | ||
const component = readdirSync(resolve(componentsDirectory, c.name)); | ||
component.forEach((mode) => { | ||
acc.components.push({ | ||
name: `${c.name}/${mode.includes("base") ? "base" : `${mode.match(/[\w\d-]+(?=.json)/)[0]}`}`, | ||
source: [resolve(componentsDirectory, c.name, `${mode}`)], | ||
references: [ | ||
...globalSourceReference, | ||
...(mode.includes("base") ? [] : [`${resolve(componentsDirectory, c.name, "base.json")}`]), | ||
], | ||
}); | ||
}); | ||
} else { | ||
acc.componentRefs.push(`${resolve(componentsDirectory, c.name)}`); | ||
} | ||
|
||
return acc; | ||
}, | ||
{ components: [], componentRefs: [] } as { components: File[]; componentRefs: string[] } | ||
) | ||
); | ||
|
||
const global: File = { | ||
name: "global", | ||
source: globalSourceReference, | ||
references: componentRefs, | ||
}; | ||
|
||
const modes = await readdir(modesDirectory).then((modes) => | ||
modes.map((mode) => ({ | ||
name: `mode/${mode.match(/[\w\d-]+(?=.json)/)[0]}`, | ||
source: [resolve(modesDirectory, `${mode}`)], | ||
references: [...globalSourceReference, ...componentRefs], | ||
})) | ||
); | ||
|
||
export const config: Config = { | ||
files: [global, ...modes, ...components], | ||
options: { | ||
prefix: "calcite", | ||
outputReferences: true, | ||
}, | ||
output: { | ||
dir: resolve(__dirname, "../dist"), | ||
platforms: ["css", "scss"], | ||
}, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
"component/fab", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole file is outdated and set to be deleted. |
||
"component/checkbox", | ||
"component/chip", | ||
"component/combobox", | ||
"component/combobox-item", | ||
"component/dropdown", | ||
"component/dropdown-item", | ||
"component/action-bar", | ||
|
@@ -21,8 +23,9 @@ | |
"component/block", | ||
"component/block-section", | ||
"component/card", | ||
"component/combobox", | ||
"component/list-item", | ||
"component/date-picker", | ||
"component/select", | ||
"component/color-picker", | ||
"component/input-date-picker", | ||
"component/input-datetime-local", | ||
|
@@ -48,13 +51,17 @@ | |
"component/tab-title", | ||
"component/tabs", | ||
"component/rating", | ||
"component/select", | ||
"component/tip", | ||
"component/tip-manager", | ||
"component/tooltip", | ||
"component/panel-header", | ||
"component/flow-header", | ||
"component/segmented-control", | ||
"component/segmented-control-item", | ||
"component/popover", | ||
"component/pagination", | ||
"component/segmented-control", | ||
"component/pagination-item", | ||
"component/slider", | ||
"component/slider-histogram", | ||
"component/slider-histogram-range", | ||
|
@@ -63,12 +70,14 @@ | |
"component/stepper-item", | ||
"component/switch", | ||
"component/[template-comp-name]", | ||
"component/progress", | ||
"component/time-picker", | ||
"component/scrim", | ||
"component/tree-item", | ||
"component/accordion_backup", | ||
"calcite/light", | ||
"calcite/dark", | ||
"calcite/grayscale", | ||
"brand/global", | ||
"brand/light", | ||
"brand/dark" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would likely need to happen on
connectedCallback()
so a component updates its mode if its moved position in the DOM.