Skip to content

Commit

Permalink
<css-color>
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaVerou committed Mar 23, 2024
1 parent 2d64fdd commit 3744ab4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
8 changes: 6 additions & 2 deletions elements/css-color/css-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ export default class CSSColor extends HTMLElement {
<div id="swatch" part="swatch"></div>
</slot>
<div id="wrapper">
<slot></slot>
<color-gamut id="gamut" part="gamut" gamuts="srgb, p3, rec2020: P3+"></color-gamut>
<slot name="before-color"></slot>
<div part="color-wrapper">
<slot></slot>
<color-gamut id="gamut" part="gamut" gamuts="srgb, p3, rec2020: P3+"></color-gamut>
</div>
<slot name="after-color"></slot>
</div>
`;
}
Expand Down
10 changes: 10 additions & 0 deletions elements/css-color/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
<input value="oklch(70% 0.25 138)" />
</css-color>

<h2>With name</h2>
<css-color>
<label slot="before-color">Accent color:</label>
<input value="oklch(70% 0.25 138)" />
</css-color>
<css-color swatch="large">
<label slot="before-color">Accent color:</label>
<input value="oklch(70% 0.25 138)" />
</css-color>

<h2>Update via JS</h2>
<h3>Static</h3>
<css-color id="dynamic_static">oklch(70% 0.25 138)</css-color>
Expand Down
22 changes: 18 additions & 4 deletions elements/css-color/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,32 @@

#wrapper {
display: flex;
position: relative;
flex-flow: inherit;

&.static {
gap: .4em;
}

&:not(.static) {

}
}

[part="color-wrapper"] {
position: relative;
display: flex;
gap: .2em;

&:not(.static *) {
#gamut {
position: absolute;
inset: .3em;
inset-inline-start: auto;
}
}

::slotted(input) {
padding-inline-end: 2em;
}
::slotted(input) {
padding-inline-end: 2em;
}
}

Expand All @@ -44,6 +54,10 @@

:host(:not([for])):host([swatch="large"]) {
flex-flow: column;

#wrapper {
flex-flow: column;
}
}

:host(:not([for])):host([swatch="large"]) #swatch {
Expand Down

0 comments on commit 3744ab4

Please sign in to comment.