-
Notifications
You must be signed in to change notification settings - Fork 622
DRAFT FOR COMMENT: Design system modularization #2559
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
Closed
Closed
Changes from all commits
Commits
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
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
62 changes: 62 additions & 0 deletions
62
packages/fast-components-styles-msft/src/utilities/color/offsets-algorithm.ts
This file contains hidden or 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,62 @@ | ||
| import { | ||
| checkDesignSystemResolver, | ||
| DesignSystem, | ||
| DesignSystemResolver, | ||
| } from "../../design-system"; | ||
| import { SwatchFamily, SwatchFamilyResolver } from "./common"; | ||
| import { findClosestBackgroundIndex, getSwatch, isDarkMode, Palette } from "./palette"; | ||
|
|
||
| /** | ||
| * Function to derive colors from offset configuration. | ||
| */ | ||
| export function offsetsAlgorithm( | ||
| palette: Palette | DesignSystemResolver<Palette>, | ||
| restDelta: number | DesignSystemResolver<number>, | ||
| hoverDelta: number | DesignSystemResolver<number>, | ||
| activeDelta: number | DesignSystemResolver<number>, | ||
| focusDelta: number | DesignSystemResolver<number> | ||
| ): SwatchFamilyResolver { | ||
| return (designSystem: DesignSystem): SwatchFamily => { | ||
| const resolvedPalette: Palette = checkDesignSystemResolver(palette, designSystem); | ||
|
|
||
| const backgroundIndex: number = findClosestBackgroundIndex(designSystem); | ||
|
|
||
| const direction: 1 | -1 = isDarkMode(designSystem) ? -1 : 1; | ||
|
|
||
| const resolvedRestDelta: number = checkDesignSystemResolver( | ||
| restDelta, | ||
| designSystem | ||
| ); | ||
| const resolvedHoverDelta: number = checkDesignSystemResolver( | ||
| hoverDelta, | ||
| designSystem | ||
| ); | ||
| const resolvedActiveDelta: number = checkDesignSystemResolver( | ||
| activeDelta, | ||
| designSystem | ||
| ); | ||
| const resolvedFocusDelta: number = checkDesignSystemResolver( | ||
| focusDelta, | ||
| designSystem | ||
| ); | ||
|
|
||
| return { | ||
| rest: getSwatch( | ||
| backgroundIndex + direction * resolvedRestDelta, | ||
| resolvedPalette | ||
| ), | ||
| hover: getSwatch( | ||
| backgroundIndex + direction * resolvedHoverDelta, | ||
| resolvedPalette | ||
| ), | ||
| active: getSwatch( | ||
| backgroundIndex + direction * resolvedActiveDelta, | ||
| resolvedPalette | ||
| ), | ||
| focus: getSwatch( | ||
| backgroundIndex + direction * resolvedFocusDelta, | ||
| resolvedPalette | ||
| ), | ||
| }; | ||
| }; | ||
| } | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Just a thought, and I know this is in the idea stage - but perhaps this algo can be defined by more of a config driven aspect? That may help those using it and reading it. It seems like the algorithm needs two things: 1) Palette, 2) interactive state config for the deltas
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.
Is the benefit here cleaner syntax, reuse of config, or both? It does seem like it would protect from potential future changes easier as properties could be added and defaulted or deprecated without changing the signature. I would probably put everything in though, including the palette. I could see an implementation of this that wants both an accent and neutral, or even success or error, etc.
Perhaps in the design system service model there would be a way for style modules like this to retrieve properties from the registry of sorts. For instance, a custom design system might add a fourth color, and through composition the style could find it. This feels like a fairly standard composition problem that possibly has a framework or structure already in place. I wonder if we could pull something in.
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.
Initially I see it for cleaner syntax - from a fn() standpoint, once you hit more than 3 inputs it's going to become difficult to manage. Considering the deltas are all "related" and inform the palette I think the syntax makes more sense than having them all at the same level.