Add the slide-out "Customize more" label back to item preview button

I skipped this for a bit because I couldn't think of a simple way to
adapt this behavior to a web component + vanilla CSS setting, but then
I thought of CSS variables, and sat down and cranked this out!
This commit is contained in:
Emi Matchu 2024-09-09 13:05:42 -07:00
parent 2ffad8120e
commit 71ffb7f1be
3 changed files with 36 additions and 1 deletions

View file

@ -81,6 +81,25 @@ class SpeciesFacePickerOptions extends HTMLElement {
}
}
class MeasuredContent extends HTMLElement {
connectedCallback() {
setTimeout(() => this.#measure(), 0);
}
#measure() {
// Find our `<measured-container>` parent, and set our natural width
// as `var(--natural-width)` in the context of its CSS styles.
const container = this.closest("measured-container");
if (container == null) {
throw new Error(
`<measured-content> must be in a <measured-container>`,
);
}
container.style.setProperty("--natural-width", this.offsetWidth + "px");
}
}
customElements.define("species-color-picker", SpeciesColorPicker);
customElements.define("species-face-picker", SpeciesFacePicker);
customElements.define("species-face-picker-options", SpeciesFacePickerOptions);
customElements.define("measured-content", MeasuredContent);

View file

@ -55,12 +55,25 @@ body.items-show
text-decoration: none
background: #EDF2F7
padding: .75em
padding-inline: .75em
border-radius: .375em
min-height: 2rem
min-width: 2rem
box-sizing: border-box
.customize-more-label
width: 0
overflow: hidden
transition: width .25s
white-space: nowrap
measured-content
padding-right: .5em
&:hover, &:focus
.customize-more-label
width: var(--natural-width)
outfit-viewer
display: block
position: relative

View file

@ -22,6 +22,9 @@
= link_to wardrobe_path(params: @preview_outfit.wardrobe_params),
class: "customize-more", target: "_blank",
title: "Customize more", "aria-label": "Customize more" do
%measured-container.customize-more-label
%measured-content
Customize more
= edit_icon
%species-color-picker