Skip to content

Commit

Permalink
New: It is now possible to set the contrast threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Oct 7, 2024
1 parent 6bed62c commit 8e56752
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Configuration/Settings.Colors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Neos:
collapsed: false
# The name of the custom property. Only used when mode is set to 'all'
customPropertyName: 'color'
# Set the color contrast threshold for the color name output. Value between 0 and 1
# Depend on the luminance, the text will be black or white
contrastThreshold: 0.6
# The presets are based on https://tailwindcss.com/docs/customizing-colors with the key 500
# false and null values get filtered out
presets:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ Neos:
customPropertyName: "color"
# The precision of the OKLCH color picker. Set to 0 to disable rounding and use the raw values.
precision: 5
# Set the color contrast threshold for the color name output. Value between 0 and 1
# Depend on the luminance, the text will be black or white
contrastThreshold: 0.6
# The presets are based on https://tailwindcss.com/docs/customizing-colors with the key 600
# false and null values get filtered out. You can also disable all presets with presets: false
presets:
Expand Down Expand Up @@ -180,6 +183,7 @@ Foo.Bar:Your.Prototype:
allowEmpty: false
collapsed: true
customPropertyName: "color-main"
contrastThreshold: "ClientEval: node.properties.contrastThresholdProperty / 100"
presets:
red: "#dc2626"
orange: "#ea580c"
Expand Down
13 changes: 9 additions & 4 deletions Resources/Private/Editor/ColorPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const defaultOptions = {
showHexInput: true,
showLightness: false,
showLuminance: false,
contrastThreshold: 0.6,
precision: 5,
presets: {},
};
Expand Down Expand Up @@ -62,7 +63,7 @@ const styles = stylex.create({
background: "none",
backgroundColor: colors.contrastNeutral,
},
popoverButtonPreview: (color, luminance) => ({
popoverButtonPreview: (color, luminance, contrastThreshold) => ({
flex: "1",
display: "flex",
alignItems: "center",
Expand All @@ -71,7 +72,7 @@ const styles = stylex.create({
minHeight: sizes.goldenUnit,
borderTopLeftRadius: sizes.borderRadius,
borderBottomLeftRadius: sizes.borderRadius,
color: luminance > 0.6 ? "black" : "white",
color: luminance > contrastThreshold ? "black" : "white",
backgroundColor: color || null,
backgroundSize: color ? null : "16px 16px",
backgroundImage: color ? null : colors.checkerboard,
Expand Down Expand Up @@ -104,7 +105,7 @@ const styles = stylex.create({
function Editor(props) {
const options = { ...defaultOptions, ...props.config, ...props.options };
const { value, commit, highlight, i18nRegistry, id } = props;
const { disabled, mode, collapsed, allowEmpty, precision } = options;
const { disabled, mode, collapsed, allowEmpty, precision, contrastThreshold } = options;
if (mode !== "coords" && mode !== "hex" && mode !== "all" && mode !== "oklch") {
return (
<div {...stylex.props(styles.error)}>
Expand Down Expand Up @@ -174,7 +175,11 @@ function Editor(props) {
aria-expanded={open}
aria-controls={`${id}-panel`}
>
<output {...stylex.props(styles.popoverButtonPreview(state?.oklch, state?.coords?.l || 0))}>
<output
{...stylex.props(
styles.popoverButtonPreview(state?.oklch, state?.coords?.l || 0, contrastThreshold),
)}
>
<Suspense fallback={<HexOutput hex={state?.hex} />}>
<ColorName hex={state?.hex} />
</Suspense>
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/ColorName.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Resources/Public/ColorName.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Resources/Public/Plugin.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
.x1bexyg0:not(#\#):not(#\#):not(#\#){line-height:calc(var(--x1fv9uxr) - 10px)}
.x190dgpg:not(#\#):not(#\#):not(#\#){opacity:.65}
.x1u4uod0:not(#\#):not(#\#):not(#\#){opacity:var(--opacity,revert)}
.xdpxx8g:not(#\#):not(#\#):not(#\#){text-align:left}
.x1hr2gdg:not(#\#):not(#\#):not(#\#){text-align:right}
.xlyipyv:not(#\#):not(#\#):not(#\#){text-overflow:ellipsis}
.x1v0jg1i:not(#\#):not(#\#):not(#\#){transform:var(--transform,revert)}
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/Plugin.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Resources/Public/Plugin.js.map

Large diffs are not rendered by default.

0 comments on commit 8e56752

Please sign in to comment.