Skip to content

Commit

Permalink
Update: Add hightlight state and improve color list
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Mar 21, 2024
1 parent c950085 commit 4c0d4e2
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 113 deletions.
25 changes: 20 additions & 5 deletions Resources/Private/Editor/ColorValuesEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function Editor(props) {
const { commit, value, highlight, i18nRegistry } = props;
const { disabled, values } = options;

const previewBoxAttributes = (value, placeholder) => {
const previewBoxAttributes = (value, highlight, placeholder) => {
const hasValue = value && Object.prototype.hasOwnProperty.call(values, value);
const color = hasValue ? values[value].color : placeholder;
const title = hasValue ? i18nRegistry.translate(values[value].label) : null;
Expand All @@ -40,6 +40,10 @@ function Editor(props) {
classNames.push(style.checkboard);
}

if (highlight) {
classNames.push(style.highlight);
}

return {
className: classNames.filter((item) => !!item).join(" "),
style: { backgroundColor: color },
Expand All @@ -64,10 +68,12 @@ function Editor(props) {
});
}

const fixedButton = valueArray.length > 9;

return (
<div className={options.disabled && style.disabled}>
<div className={style.wrapper}>
<div {...previewBoxAttributes(value, options.placeholder)}></div>
<div {...previewBoxAttributes(value, highlight, options.placeholder)}></div>
{allowEmpty && (
<div className={style.reset}>
<IconButton
Expand All @@ -80,17 +86,26 @@ function Editor(props) {
)}
</div>
<div className={style.list}>
{valueArray.map((item) => {
{valueArray.map((item, index) => {
return item.color ? (
<button
className={[style.item, item.color == "transparent" && style.transparent].join(" ")}
key={index}
className={[
style.item,
item.color == "transparent" && style.transparent,
fixedButton && style.itemFixed,
]
.filter((item) => !!item)
.join(" ")}
disabled={item.disabled}
style={{ backgroundColor: item.color }}
title={item.label}
onClick={() => commit(item.key)}
></button>
) : (
<div className={style.label}>{item.label}</div>
<div key={index} className={style.label}>
{item.label}
</div>
);
})}
</div>
Expand Down
23 changes: 16 additions & 7 deletions Resources/Private/Editor/ColorValuesEditor/style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
padding: 10px 16px;
}

.highlight {
box-shadow: 0 0 0 2px #ff8700;
}

.feedback {
flex: 1;
height: 40px;
border: 1px solid #3f3f3f;
border-radius: 2px;
}

.transparent,
Expand All @@ -30,11 +35,11 @@
flex: 1;
position: relative;
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
justify-content: space-between;
gap: 10px;
margin-top: 10px;
padding-top: 15px;
gap: 8px;
margin-top: 8px;
padding-top: 8px;
border-top: 1px solid #3f3f3f;
}

Expand All @@ -46,10 +51,14 @@
.item {
border: 1px solid #3f3f3f;
border-radius: 2px;
width: 18px;
height: 18px;
height: 24px;
cursor: pointer;
flex: 0 0 18px;
flex: 1 0 24px;
padding: 0;
}

.itemFixed {
flex-grow: 0;
}

.item:hover,
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/Plugin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Resources/Public/Plugin.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Resources/Public/Plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4c0d4e2

Please sign in to comment.