-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coloured tokens multi visualisation (#41)
Co-authored-by: Alan <41682961+alan-cooney@users.noreply.github.com>
- Loading branch information
1 parent
5563526
commit f80525e
Showing
8 changed files
with
540 additions
and
5 deletions.
There are no files selected for viewing
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
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,113 @@ | ||
import { AnyColor } from "colord"; | ||
import React from "react"; | ||
import { TokenCustomTooltip } from "./utils/TokenCustomTooltip"; | ||
|
||
/** | ||
* Display tokens with a background representing how negative (close to | ||
* `negativeColor`) or positive (close to `positiveColor`) the token is. Zero is | ||
* always displayed as white. | ||
* | ||
* Hover over a token, to view its value. | ||
*/ | ||
export function ColoredTokensCustomTooltips({ | ||
maxValue, | ||
minValue, | ||
negativeColor, | ||
positiveColor, | ||
tokens, | ||
values, | ||
tooltips | ||
}: ColoredTokensCustomTooltipsProps) { | ||
const tokenMin = minValue ?? Math.min(...values); | ||
const tokenMax = maxValue ?? Math.max(...values); | ||
|
||
return ( | ||
<div className="colored-tokens" style={{ paddingBottom: 30 }}> | ||
{tokens.map((token, key) => ( | ||
<TokenCustomTooltip | ||
key={key} | ||
token={token} | ||
value={values[key]} | ||
min={tokenMin} | ||
max={tokenMax} | ||
negativeColor={negativeColor} | ||
positiveColor={positiveColor} | ||
tooltip={tooltips[key]} | ||
/> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export interface ColoredTokensCustomTooltipsProps { | ||
/** | ||
* Maximum value | ||
* | ||
* Used to determine how dark the token color is when positive (i.e. based on | ||
* how close it is to the minimum value). | ||
* | ||
* @default Math.max(...values) | ||
*/ | ||
maxValue?: number; | ||
|
||
/** | ||
* Minimum value | ||
* | ||
* Used to determine how dark the token color is when negative (i.e. based on | ||
* how close it is to the minimum value). | ||
* | ||
* @default Math.min(...values) | ||
*/ | ||
minValue?: number; | ||
|
||
/** | ||
* Negative color | ||
* | ||
* Color to use for negative values. This can be any valid CSS color string. | ||
* | ||
* Be mindful of color blindness if not using the default here. | ||
* | ||
* @default "red" | ||
* | ||
* @example rgb(255, 0, 0) | ||
* | ||
* @example #ff0000 | ||
*/ | ||
negativeColor?: AnyColor; | ||
|
||
/** | ||
* Positive color | ||
* | ||
* Color to use for positive values. This can be any valid CSS color string. | ||
* | ||
* Be mindful of color blindness if not using the default here. | ||
* | ||
* @default "blue" | ||
* | ||
* @example rgb(0, 0, 255) | ||
* | ||
* @example #0000ff | ||
*/ | ||
positiveColor?: AnyColor; | ||
|
||
/** | ||
* List of tokens | ||
* | ||
* Must be the same length as the list of values. | ||
*/ | ||
tokens: string[]; | ||
|
||
/** | ||
* Values for each token | ||
* | ||
* Must be the same length as the list of tokens. | ||
*/ | ||
values: number[]; | ||
|
||
/** | ||
* Tooltips for each token | ||
* | ||
* Must be the same length as the list of tokens. | ||
*/ | ||
tooltips: React.ReactNode[]; | ||
} |
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,19 @@ | ||
import { ComponentStory, ComponentMeta } from "@storybook/react"; | ||
import React from "react"; | ||
import { mockTokens, mockValues, mockLabels } from "./mocks/coloredTokensMulti"; | ||
import { ColoredTokensMulti } from "./ColoredTokensMulti"; | ||
|
||
export default { | ||
component: ColoredTokensMulti | ||
} as ComponentMeta<typeof ColoredTokensMulti>; | ||
|
||
const Template: ComponentStory<typeof ColoredTokensMulti> = (args) => ( | ||
<ColoredTokensMulti {...args} /> | ||
); | ||
|
||
export const SmallModelExample = Template.bind({}); | ||
SmallModelExample.args = { | ||
tokens: mockTokens, | ||
values: mockValues, | ||
labels: mockLabels | ||
}; |
Oops, something went wrong.