Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templates Improvements #1144

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/snap-preact-demo/templates/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ new SnapTemplates({
global: {
extends: 'bocachica',
variables: {
color: {
colors: {
primary: 'red',
secondary: 'blue',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ const CSS = {
display: 'inline-flex',
padding: '5px 10px',
position: 'relative',
color: color || theme?.variables?.color?.primary,
color: color || theme?.variables?.colors?.primary,
outline: 0,
backgroundColor: backgroundColor || '#fff',
border: `1px solid ${borderColor || color || theme?.variables?.color?.primary || '#333'}`,
border: `1px solid ${borderColor || color || theme?.variables?.colors?.primary || '#333'}`,
'&:hover': {
cursor: 'pointer',
backgroundColor: theme?.variables?.color?.hover?.background || '#f8f8f8',
backgroundColor: theme?.variables?.colors?.hover?.background || '#f8f8f8',
},
'&.ss__button--disabled': {
opacity: 0.7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { mergeProps } from '../../../utilities';
const CSS = {
icon: ({ color, height, width, size, theme }: Partial<IconProps>) =>
css({
fill: color || theme?.variables?.color?.primary || '#333',
stroke: color || theme?.variables?.color?.primary || '#333',
fill: color || theme?.variables?.colors?.primary || '#333',
stroke: color || theme?.variables?.colors?.primary || '#333',
width: isNaN(Number(width || size)) ? width || size : `${width || size}px`,
height: isNaN(Number(height || size)) ? height || size : `${height || size}px`,
position: 'relative',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ const CSS = {
opacity: '1',
visibility: 'visible',
zIndex: '10000',
background: backgroundColor || theme?.variables?.color?.secondary || '#f8f8f8',
background: backgroundColor || theme?.variables?.colors?.secondary || '#f8f8f8',

'& .ss__loading-bar__bar': {
position: 'absolute',
top: '0',
left: '-200px',
height: '100%',
background: `${color || theme?.variables?.color?.primary || '#ccc'}`,
background: `${color || theme?.variables?.colors?.primary || '#ccc'}`,
animation: `${animation} 2s linear infinite`,
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ export default {
},
layout: {
description: 'Banner layout',
defaultValue: ResultsLayout.GRID,
defaultValue: ResultsLayout.grid,
table: {
type: {
summary: 'string',
},
},
options: [ResultsLayout.GRID, ResultsLayout.LIST],
options: [ResultsLayout.grid, ResultsLayout.list],
control: {
type: 'select',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Fragment, h } from 'preact';
import { jsx, css } from '@emotion/react';
import classnames from 'classnames';
import { Theme, useTheme, CacheProvider } from '../../../../providers';
import { ComponentProps, ResultsLayout, ResultsLayoutType, RootNodeProperties } from '../../../../types';
import { ComponentProps, ResultsLayout, RootNodeProperties } from '../../../../types';
import { mergeProps } from '../../../../utilities';

import type { Banner } from '@searchspring/snap-store-mobx';
Expand Down Expand Up @@ -34,7 +34,7 @@ const CSS = {
export function InlineBanner(properties: InlineBannerProps): JSX.Element {
const globalTheme: Theme = useTheme();
const defaultProps: Partial<InlineBannerProps> = {
layout: ResultsLayout.GRID,
layout: ResultsLayout.grid,
width: 'auto',
};

Expand Down Expand Up @@ -74,6 +74,6 @@ export function InlineBanner(properties: InlineBannerProps): JSX.Element {
export interface InlineBannerProps extends ComponentProps {
banner: Banner;
width?: string;
layout?: ResultsLayoutType;
layout?: keyof typeof ResultsLayout | ResultsLayout;
onClick?: (e: React.MouseEvent, banner: Banner) => void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { mergeProps } from '../../../utilities';
const CSS = {
price: ({ theme }: Partial<PriceProps>) =>
css({
color: theme?.variables?.color?.primary,
color: theme?.variables?.colors?.primary,
'&.ss__price--strike': {
textDecoration: 'line-through',
color: 'initial',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const CSS = {
},
},
'.swiper-pagination-bullet-active': {
background: theme?.variables?.color?.primary || 'inherit',
background: theme?.variables?.colors?.primary || 'inherit',
},
'.ss__carousel__next-wrapper, .ss__carousel__prev-wrapper': {
display: 'flex',
Expand Down Expand Up @@ -130,7 +130,7 @@ const CSS = {
margin: '0 4px',
'&.swiper-pagination-bullet-active': {
opacity: '0.8',
background: theme?.variables?.color?.primary || '#000',
background: theme?.variables?.colors?.primary || '#000',
},
},
'.swiper-slide-invisible-blank': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const CSS = {
justifyContent: 'center',
height: pixelSize,
width: pixelSize,
border: `1px solid ${color || theme?.variables?.color?.primary || '#333'}`,
border: `1px solid ${color || theme?.variables?.colors?.primary || '#333'}`,
'&.ss__checkbox--disabled': {
opacity: 0.7,
},
Expand Down Expand Up @@ -76,7 +76,7 @@ export const Checkbox = observer((properties: CheckboxProps): JSX.Element => {
...globalTheme?.components?.icon,
// inherited props
...defined({
color: iconColor || color || theme?.variables?.color?.primary,
color: iconColor || color || theme?.variables?.colors?.primary,
disableStyles,
icon,
size: size && `calc(${pixelSize} - 30%)`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const CSS = {
'& .ss__error-handler__button': {
backgroundColor: 'white',
color: 'inherit',
borderColor: theme?.variables?.color?.primary,
borderColor: theme?.variables?.colors?.primary,
width: ['150px', 'fit-content'],
margin: '5px 10px',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const CSS = {
justifyContent: 'center',
alignItems: 'center',
flex: '0 1 auto',
border: `1px solid ${theme?.variables?.color?.primary || '#333'}`,
border: `1px solid ${theme?.variables?.colors?.primary || '#333'}`,
textAlign: 'center',
wordBreak: 'break-all',
boxSizing: 'border-box',
Expand All @@ -38,12 +38,12 @@ const CSS = {
marginRight: '0',
},
'&.ss__facet-grid-options__option--filtered': {
background: theme?.variables?.color?.primary || '#ccc',
color: theme?.variables?.color?.secondary,
background: theme?.variables?.colors?.primary || '#ccc',
color: theme?.variables?.colors?.secondary,
},
'&:hover:not(.ss__facet-grid-options__option--filtered)': {
cursor: 'pointer',
background: theme?.variables?.color?.hover?.background || '#f8f8f8',
background: theme?.variables?.colors?.hover?.background || '#f8f8f8',
},
'& .ss__facet-grid-options__option__value': {
'&.ss__facet-grid-options__option__value--smaller': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const CSS = {
alignItems: 'center',
'&:hover': {
cursor: 'pointer',
background: theme?.variables?.color?.hover?.background,
background: theme?.variables?.colors?.hover?.background,
},
'&.ss__facet-hierarchy-options__option--filtered': {
fontWeight: 'bold',
color: theme?.variables?.color?.primary,
color: theme?.variables?.colors?.primary,
'&:hover': {
cursor: 'default',
background: 'unset',
Expand All @@ -39,7 +39,7 @@ const CSS = {
'&:before': {
content: `'\\0000ab'`,
padding: '0 2px 0 0',
color: theme?.variables?.color?.primary,
color: theme?.variables?.colors?.primary,
},
},
'& .ss__facet-hierarchy-options__option__value': {
Expand All @@ -63,11 +63,11 @@ const CSS = {

'&:hover': {
cursor: 'pointer',
background: theme?.variables?.color?.hover?.background,
background: theme?.variables?.colors?.hover?.background,
},
'&.ss__facet-hierarchy-options__option--filtered': {
fontWeight: 'bold',
color: theme?.variables?.color?.primary,
color: theme?.variables?.colors?.primary,
marginRight: '2em',
'&:hover': {
cursor: 'default',
Expand All @@ -78,7 +78,7 @@ const CSS = {
'&:before': {
content: `'\\0000ab'`,
padding: '0 2px 0 0',
color: theme?.variables?.color?.primary,
color: theme?.variables?.colors?.primary,
},
},
'& .ss__facet-hierarchy-options__option__value': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const CSS = {
textDecoration: 'none',
'&:hover': {
cursor: 'pointer',
background: theme?.variables?.color?.hover?.background,
background: theme?.variables?.colors?.hover?.background,
},
'&.ss__facet-list-options__option--filtered': {
fontWeight: 'bold',
color: theme?.variables?.color?.primary,
color: theme?.variables?.colors?.primary,
},
'& .ss__facet-list-options__option__value': {
marginLeft: hideCheckbox ? '' : '8px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const CSS = {
},
'&.ss__facet-palette-options__option--filtered': {
'& .ss__facet-palette-options__option__wrapper': {
borderColor: theme?.variables?.color?.primary || '#333',
borderColor: theme?.variables?.colors?.primary || '#333',
padding: '0px',
borderWidth: '4px',
},
Expand Down Expand Up @@ -129,7 +129,7 @@ const CSS = {

'.ss__facet-palette-options__option--filtered': {
'& .ss__facet-palette-options__option__wrapper': {
borderColor: theme?.variables?.color?.primary || '#333' + ' !important',
borderColor: theme?.variables?.colors?.primary || '#333' + ' !important',
padding: '0px',
borderWidth: '4px',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ const CSS = {
},
},
'& .ss__facet-slider__rail': {
background: railColor || theme?.variables?.color?.primary || '#333',
background: railColor || theme?.variables?.colors?.primary || '#333',
height: '100%',
},
'& .ss__facet-slider__segment': {
background: trackColor || theme?.variables?.color?.secondary || '#ccc',
background: trackColor || theme?.variables?.colors?.secondary || '#ccc',
height: '100%',
},
'& .ss__facet-slider__handles': {
textAlign: 'center',
'& button': {
'& .ss__facet-slider__handle': {
background: handleColor || theme?.variables?.color?.primary || '#333',
background: handleColor || theme?.variables?.colors?.primary || '#333',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
Expand Down Expand Up @@ -104,7 +104,7 @@ const CSS = {
},

'&.ss__facet-slider__handle--active': {
background: handleDraggingColor || handleColor || theme?.variables?.color?.primary || '#000',
background: handleDraggingColor || handleColor || theme?.variables?.colors?.primary || '#000',
'& label.ss__facet-slider__handle__label': {
background: '#fff',
padding: '0 5px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const CSS = {
justifyContent: 'center',
alignItems: 'center',
flex: '0 1 auto',
border: `1px solid ${theme?.variables?.color?.primary || '#333'}`,
border: `1px solid ${theme?.variables?.colors?.primary || '#333'}`,
textAlign: 'center',
wordBreak: 'break-all',
padding: '1em 0',
Expand All @@ -47,7 +47,7 @@ const CSS = {
marginRight: '0',
},
'&.ss__grid__option--selected': {
border: `2px solid ${theme?.variables?.color?.primary || '#333'}`,
border: `2px solid ${theme?.variables?.colors?.primary || '#333'}`,
},

'&.ss__grid__option--disabled': {
Expand Down Expand Up @@ -76,7 +76,7 @@ const CSS = {

'&:hover:not(.ss__grid__option--selected)': {
cursor: 'pointer',
background: theme?.variables?.color?.hover?.background || '#f8f8f8',
background: theme?.variables?.colors?.hover?.background || '#f8f8f8',
},
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ const CSS = {
gap: '5px',
'& .ss__load-more__progress__indicator': {
width: progressIndicatorWidth,
background: backgroundColor || theme?.variables?.color?.secondary || '#f8f8f8',
background: backgroundColor || theme?.variables?.colors?.secondary || '#f8f8f8',
borderRadius: progressIndicatorSize,
'& .ss__load-more__progress__indicator__bar': {
width: pagination ? `${(pagination.end / pagination.totalResults) * 100}%` : '',
background: color || theme?.variables?.color?.primary || '#ccc',
background: color || theme?.variables?.colors?.primary || '#ccc',
borderRadius: progressIndicatorSize,
height: progressIndicatorSize,
},
Expand All @@ -80,7 +80,7 @@ const CSS = {

'& .ss__load-more__progress__indicator': {
'& .ss__load-more__progress__indicator__radial': {
background: backgroundColor || theme?.variables?.color?.secondary || '#f8f8f8',
background: backgroundColor || theme?.variables?.colors?.secondary || '#f8f8f8',
height: progressIndicatorWidth,
width: progressIndicatorWidth,
borderRadius: '50%',
Expand Down Expand Up @@ -113,7 +113,7 @@ const CSS = {
'& .ss__load-more__progress__indicator__radial__mask': {
'& .ss__load-more__progress__indicator__radial__mask__fill': {
clipPath: `inset(0px calc((${progressIndicatorWidth} / 2)) 0px 0px)`,
backgroundColor: color || theme?.variables?.color?.primary || '#ccc',
backgroundColor: color || theme?.variables?.colors?.primary || '#ccc',
},
'&.ss__load-more__progress__indicator__radial__mask--full': {
transform: `rotate(${radialAngle}deg)`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const CSS = {
fontWeight: 'bold',
},
'&:hover:not(.ss__pagination__page--active)': {
backgroundColor: theme?.variables?.color?.hover?.background || '#f8f8f8',
backgroundColor: theme?.variables?.colors?.hover?.background || '#f8f8f8',
},
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ export default {
},
layout: {
description: 'Results layout',
defaultValue: ResultsLayout.GRID,
defaultValue: ResultsLayout.grid,
table: {
type: {
summary: 'string',
},
},
options: [ResultsLayout.GRID, ResultsLayout.LIST],
options: [ResultsLayout.grid, ResultsLayout.list],
control: {
type: 'select',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ describe('Result Component', () => {
});

it('should can change the layout', () => {
const rendered = render(<Result result={mockResults[1] as Product} layout={ResultsLayout.LIST} />);
const rendered = render(<Result result={mockResults[1] as Product} layout={ResultsLayout.list} />);
const Element = rendered.container.querySelector('.ss__result');
expect(Element).toHaveClass(`ss__result--${ResultsLayout.LIST}`);
expect(Element).toHaveClass(`ss__result--${ResultsLayout.list}`);
});

it('can truncate the title', () => {
Expand Down
Loading
Loading