Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ export default {
},
control: { type: 'boolean' },
},
hideCountParenthesis: {
defaultValue: false,
description: 'Hide facet option count parenthesis',
table: {
type: {
summary: 'boolean',
},
defaultValue: { summary: false },
},
control: { type: 'boolean' },
},
previewOnFocus: {
description: 'Invoke facet value preview upon focus',
table: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ describe('ListValue Component hiding checkbox and count', () => {
});

describe('FacetListOptions generic props work', () => {
it('can hide count parenthesis', () => {
const rendered = render(<FacetListOptions values={listFacetMock.values as FacetValue[]} hideCountParenthesis={true} />);

const listOption = rendered.container.querySelectorAll('.ss__facet-list-options__option');

expect(listOption).toHaveLength(listFacetMock.values!.length);

expect(listOption[0]).toHaveTextContent(listFacetMock.values![0].label!);

const optionCount = listOption[0].querySelector('.ss__facet-list-options__option__value__count');
expect(optionCount).toHaveTextContent(listFacetMock.values![0].count!.toString());
expect(optionCount).not.toHaveTextContent('(');
expect(optionCount).not.toHaveTextContent(')');
});

it('can disable styling', () => {
const rendered = render(<FacetListOptions values={listFacetMock.values as FacetValue[]} disableStyles={true} />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export const FacetListOptions = observer((properties: FacetListOptionsProps): JS
...properties.theme?.components?.facetListOptions,
};

const { values, hideCheckbox, hideCount, onClick, previewOnFocus, valueProps, facet, disableStyles, className, style } = props;
const { values, hideCheckbox, hideCount, hideCountParenthesis, onClick, previewOnFocus, valueProps, facet, disableStyles, className, style } =
props;

const subProps: FacetListOptionsSubProps = {
checkbox: {
Expand Down Expand Up @@ -102,7 +103,9 @@ export const FacetListOptions = observer((properties: FacetListOptionsProps): JS
{!hideCheckbox && <Checkbox {...subProps.checkbox} checked={value.filtered} disableA11y={true} />}
<span className="ss__facet-list-options__option__value">
{value.label}
{!hideCount && value?.count > 0 && <span className="ss__facet-list-options__option__value__count">({value.count})</span>}
{!hideCount && value?.count > 0 && (
<span className="ss__facet-list-options__option__value__count">{hideCountParenthesis ? `${value.count}` : `(${value.count})`}</span>
)}
</span>
</a>
))}
Expand All @@ -117,6 +120,7 @@ export interface FacetListOptionsProps extends ComponentProps {
values?: FacetValue[];
hideCheckbox?: boolean;
hideCount?: boolean;
hideCountParenthesis?: boolean;
facet?: ValueFacet;
onClick?: (e: React.MouseEvent) => void;
previewOnFocus?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ The `hideCount` prop will disable the facet count values.
<FacetListOptions values={listFacet.values} hideCount={true} />
```

### hideCountParenthesis
The `hideCountParenthesis` prop will disable the facet count parenthesis from rendering.

```jsx
<FacetListOptions values={listFacet.values} hideCountParenthesis={true} />
```

### previewOnFocus
If using within Autocomplete, the `previewOnFocus` prop will invoke the `value.preview()` method when the value has been hovered over.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ export default {
},
action: 'onSelect',
},
hideSelectedOptionParentheses: {
defaultValue: false,
description: 'Hide selected option parenthesis',
table: {
type: {
summary: 'boolean',
},
defaultValue: { summary: false },
},
control: { type: 'boolean' },
},
...componentArgs,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const VariantSelection = observer((properties: VariantSelectionProps): JS
...properties.theme?.components?.variantSelection,
};

const { type, selection, onSelect, disableStyles, className, style } = props;
const { type, selection, onSelect, hideSelectedOptionParentheses, disableStyles, className, style } = props;

const onSelectHandler = (e: React.MouseEvent<HTMLElement, MouseEvent>, option: ListOption) => {
if (onSelect) {
Expand Down Expand Up @@ -171,7 +171,9 @@ export const VariantSelection = observer((properties: VariantSelectionProps): JS
<span className="ss__dropdown__button-wrapper__label">{selection.label}</span>

{selection.selected ? (
<span className="ss__dropdown__button-wrapper__selection">({selection.selected.value})</span>
<span className="ss__dropdown__button-wrapper__selection">
{hideSelectedOptionParentheses ? `${selection.selected.value}` : `(${selection.selected.value})`}
</span>
) : (
<></>
)}
Expand Down Expand Up @@ -241,4 +243,5 @@ export interface VariantSelectionProps extends ComponentProps {
selection: VariantSelectionType;
type?: 'dropdown' | 'swatches' | 'list';
onSelect?: (e: React.MouseEvent<HTMLElement, MouseEvent>, option: ListOption) => void;
hideSelectedOptionParentheses: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ The `onSelect` prop allows you to provide a callback function that is triggered

```jsx
<VariantSelection selection={VariantSelection} type={'swatches'} onSelect={(e, val) => console.log(e, val)}/>
```

### hideSelectedOptionParentheses
The `hideSelectedOptionParentheses` prop will disable the selected option parenthesis from rendering.

```jsx
<VariantSelection selection={VariantSelection} hideSelectedOptionParentheses={true} />
```
Loading