Skip to content

Commit

Permalink
Replace ColorPreviewInput preview box with 'color' input (#3271)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin authored Mar 10, 2022
1 parent 5045254 commit be1b571
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
9 changes: 3 additions & 6 deletions js/src/common/components/ColorPreviewInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@ import classList from '../utils/classList';
import icon from '../helpers/icon';

export default class ColorPreviewInput extends Component {
value?: string;

view(vnode: Mithril.Vnode<ComponentAttrs, this>) {
const { className, ...attrs } = this.attrs;
const value = attrs.bidi?.() || attrs.value;
const { className, id, ...attrs } = this.attrs;

attrs.type ||= 'text';

return (
<div className="ColorInput">
<input className={classList('FormControl', className)} {...attrs} />
<input className={classList('FormControl', className)} id={id} {...attrs} />

<span className="ColorInput-icon" role="presentation">
{icon('fas fa-exclamation-circle')}
</span>

<div className="ColorInput-preview" style={{ '--input-value': value }} role="presentation" />
<input className="ColorInput-preview" {...attrs} type="color" />
</div>
);
}
Expand Down
18 changes: 16 additions & 2 deletions less/common/ColorInput.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,26 @@
bottom: 8px;
width: 20px;
height: 20px;
pointer-events: none;
}

&-preview {
background-color: var(--input-value);
display: inline-block;
border-radius: 15%;
padding: 0;
cursor: pointer;
overflow: hidden;

// Match both the wrapper div and the div with the background color
&, &::-webkit-color-swatch-wrapper, &::-webkit-color-swatch {
border: none;
padding: 0;
}

// This has to be a separate entry so other browsers
// don't ignore the entire CSS rule. Thanks Firefox.
&::-moz-color-swatch {
border: none;
}
}

&-icon {
Expand Down

0 comments on commit be1b571

Please sign in to comment.