-
Notifications
You must be signed in to change notification settings - Fork 5
Add aliases to colors palettes #13
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Renders a color swatch with a readable text. | ||
|
||
```jsx harmony | ||
<ColorSwatch token={"accent"} value={"#C0100F"} /> | ||
<ColorSwatch token={"accent"} aliases={"error"} value={"#C0100F"} /> | ||
``` | ||
|
||
When clicked, the value of the token is copied to clipboard. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
```jsx harmony | ||
import theme from "../theme"; | ||
|
||
<Colors theme={theme} />; | ||
<Colors theme={theme} aliasesKey={"aliases"} />; | ||
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. Same here. Leave the basic example and add an advanced one where you explain why it's like this. I don't like the |
||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,29 @@ const palette = [ | |
"#C62828", | ||
"#B71C1C" | ||
]; | ||
<PaletteSwatch token={"red"} value={palette} />; | ||
palette.aliases = [ | ||
"lightest", | ||
"light", | ||
"diabled", | ||
"inactive", | ||
"regular", | ||
"hovered", | ||
"errorLight", | ||
["error", "failure"], | ||
"errorDark" | ||
]; | ||
|
||
<PaletteSwatch token={"red"} value={palette} aliasesKey="aliases" />; | ||
Comment on lines
+17
to
+29
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 example is overwhelming for me. Here is an example from the spec: https://styled-system.com/theme-specification#space which I'd suggest using. |
||
``` | ||
|
||
as well as object notation: | ||
|
||
```jsx harmony | ||
import theme from "../theme"; | ||
|
||
<PaletteSwatch token={"slate"} value={theme.colors.slate} />; | ||
<PaletteSwatch | ||
token={"slate"} | ||
value={theme.colors.slate} | ||
aliasesKey="aliases" | ||
/>; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
const Swatches = ({ items = [], children }) => ( | ||
const Swatches = ({ items = [], aliasesKey, children }) => ( | ||
<> | ||
{Array.isArray(items) | ||
? items.map((value, index) => children(index, value)) | ||
: Object.keys(items).map(key => children(key, items[key]))} | ||
? items.map((value, index) => | ||
children( | ||
index, | ||
value, | ||
aliasesKey && items[aliasesKey] ? items[aliasesKey][index] : null | ||
) | ||
) | ||
: Object.keys(items) | ||
.filter(key => key !== aliasesKey) | ||
.map(key => | ||
children( | ||
key, | ||
items[key], | ||
aliasesKey && items[aliasesKey] ? items[aliasesKey][key] : null | ||
) | ||
)} | ||
Comment on lines
+7
to
+22
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. TBH I'm not sure I want to accept this code into the repo. Maybe the best course of action would be to do this in your repo after all. You can compose things with Thoughts? 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. Maybe we can just use this repo to create a custom library? The only component which can be reused without any change is 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. I'm not sure yet. I'd like to support aliases but I'm not sure the code complexity is worth it. Is there a simpler way of getting aliases for tokens? Ideally, as the user, I should not care about providing alias keys to the library. Let me poke with it a bit and let you know. |
||
</> | ||
); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,15 @@ const palette = { | |
base: "#2E3D49", | ||
light: "#6D7780", | ||
lighter: "#B4B9BD", | ||
lightest: "#F7F7F8" | ||
lightest: "#F7F7F8", | ||
aliases: { | ||
darker: "foused", | ||
dark: "active", | ||
base: "default", | ||
light: "hovered", | ||
lighter: "disabled", | ||
lightest: "inactive" | ||
} | ||
Comment on lines
+13
to
+20
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. Why did that change? |
||
} | ||
}; | ||
export default { | ||
|
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.
Let's create a separate example for aliases. Also the name suggests it should be an array but it's a string. I also don't see any propTypes definitions for that prop.