Skip to content

Commit

Permalink
highlight variant attribute feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tobi-or-not-tobi committed Aug 1, 2024
1 parent 1dbb2fa commit 032021c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
24 changes: 22 additions & 2 deletions libs/domain/product/attributes/src/attributes.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { ProductAttributesOptions } from './attributes.model';
import { productAttributeStyles } from './attributes.styles';

@ssrShim('style')
@defaultOptions({ columnCount: '2' })
@defaultOptions({
columnCount: '2',
...(featureVersion >= '1.5' ? { highlightVariantAttribute: true } : {}),
})
@hydrate({ context: featureVersion >= '1.4' ? PRODUCT : ProductContext.SKU })
export class ProductAttributesComponent extends ProductMixin(
ContentMixin<ProductAttributesOptions>(LitElement)
Expand All @@ -23,13 +26,30 @@ export class ProductAttributesComponent extends ProductMixin(
${Object.keys(names).map(
(key) => html`
<dt>${this.getName(names, key)}</dt>
<dd>${values[key]}</dd>
<dd ?highlight=${this.isHighlighted(key)}>${values[key]}</dd>
`
)}
</dl>
`;
}

/**
* Highlighted attributes will clarify the uniqueness of the value among
* the variants.
*
* Indicates whether the attribute value should be highlighted, based on
* a global component configuration and if the attribute is part of the
* variant definition.
*
* @since 1.5
*/
protected isHighlighted(key: string): boolean {
const { variantDefinition } = this.$product() ?? {};
return (
!!this.$options().highlightVariantAttribute && !!variantDefinition?.[key]
);
}

protected getName(
names: Record<string, string>,
key: string
Expand Down
8 changes: 8 additions & 0 deletions libs/domain/product/attributes/src/attributes.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export interface ProductAttributesOptions {
columnCount?: string;
/**
* Highlighted variant attributes will clarify the uniqueness of the value among
* the variants. If the attribute is unqieu to the variant, a highlight attribute
* is added, so that the stylesheet can mark the attribute value.
*
* @since 1.5
*/
highlightVariantAttribute?: boolean;
}
9 changes: 9 additions & 0 deletions libs/domain/product/attributes/src/attributes.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ export const productAttributeStyles = css`
margin-block: 10px 20px;
color: var(--oryx-color-neutral-9);
}
dd[highlight] {
background: var(--oryx-color-primary-5);
color: var(--oryx-color-primary-10);
border-radius: 8px;
padding: 1px 6px;
margin-inline-start: -6px;
width: fit-content;
}
`;

0 comments on commit 032021c

Please sign in to comment.