|
| 1 | +import {Meta} from '@storybook/addon-docs/blocks'; |
| 2 | +import * as AtomicRatingRangeFacetStories from './atomic-rating-range-facet.new.stories'; |
| 3 | +import {AtomicDocTemplate} from '../../../../../storybook-utils/documentation/atomic-doc-template'; |
| 4 | + |
| 5 | +<Meta of={AtomicRatingRangeFacetStories} /> |
| 6 | + |
| 7 | +<AtomicDocTemplate |
| 8 | + stories={AtomicRatingRangeFacetStories} |
| 9 | + githubPath="search/facets/atomic-rating-range-facet/atomic-rating-range-facet.ts" |
| 10 | + tagName="atomic-rating-range-facet" |
| 11 | + className="AtomicRatingRangeFacet" |
| 12 | +> |
| 13 | + |
| 14 | +The `atomic-rating-range-facet` component displays a facet of the results for the current query as star ratings. It allows users to filter results based on rating ranges (e.g., "4 and up", "3 and up"). |
| 15 | + |
| 16 | +This component only supports numeric fields and is designed to work with rating data typically stored as numeric values (e.g., 1-5 stars). |
| 17 | + |
| 18 | +```html |
| 19 | +<atomic-search-interface> |
| 20 | + ... |
| 21 | + <atomic-search-layout> |
| 22 | + <atomic-layout-section section="facets"> |
| 23 | + |
| 24 | + <atomic-rating-range-facet |
| 25 | + field="rating" |
| 26 | + label="Customer Rating" |
| 27 | + number-of-intervals="5"> |
| 28 | + </atomic-rating-range-facet> |
| 29 | + |
| 30 | + </atomic-layout-section> |
| 31 | + ... |
| 32 | + </atomic-search-layout> |
| 33 | +</atomic-search-interface> |
| 34 | +``` |
| 35 | + |
| 36 | +## Key Features |
| 37 | + |
| 38 | +- **Visual Rating Display**: Shows ratings as star icons for intuitive user understanding |
| 39 | +- **Range-Based Filtering**: Provides "and up" filtering (e.g., "4 stars and up") |
| 40 | +- **Customizable Intervals**: Configure the number of rating levels to display |
| 41 | +- **Custom Icons**: Use custom SVG icons instead of default stars |
| 42 | +- **Tab Integration**: Show/hide facet based on active tabs |
| 43 | +- **Conditional Display**: Show facet based on other facet selections using `depends-on` |
| 44 | + |
| 45 | +## Configuration |
| 46 | + |
| 47 | +### Basic Configuration |
| 48 | + |
| 49 | +The `field` attribute specifies which numeric field in your index contains the rating data: |
| 50 | + |
| 51 | +```html |
| 52 | +<atomic-rating-range-facet |
| 53 | + field="snrating" |
| 54 | + label="Star Rating"> |
| 55 | +</atomic-rating-range-facet> |
| 56 | +``` |
| 57 | + |
| 58 | +### Customizing Rating Levels |
| 59 | + |
| 60 | +Control the number of rating levels and the maximum/minimum values: |
| 61 | + |
| 62 | +```html |
| 63 | +<atomic-rating-range-facet |
| 64 | + field="rating" |
| 65 | + number-of-intervals="5" |
| 66 | + max-value-in-index="5" |
| 67 | + min-value-in-index="1"> |
| 68 | +</atomic-rating-range-facet> |
| 69 | +``` |
| 70 | + |
| 71 | +- **`number-of-intervals`**: Number of rating options to display (default: 5) |
| 72 | +- **`max-value-in-index`**: Maximum rating value in your data (default: same as `number-of-intervals`) |
| 73 | +- **`min-value-in-index`**: Minimum rating value in your data (default: 1) |
| 74 | + |
| 75 | +### Custom Icons |
| 76 | + |
| 77 | +Replace the default star icon with a custom SVG: |
| 78 | + |
| 79 | +```html |
| 80 | +<atomic-rating-range-facet |
| 81 | + field="rating" |
| 82 | + icon="assets://heart.svg"> |
| 83 | +</atomic-rating-range-facet> |
| 84 | +``` |
| 85 | + |
| 86 | +You can use: |
| 87 | +- URLs starting with `http://`, `https://`, `./`, or `../` to load external icons |
| 88 | +- `assets://` prefix to use icons from the Atomic package |
| 89 | +- Inline SVG strings |
| 90 | + |
| 91 | +Make sure your custom icon includes `fill="currentColor"` to allow color customization via CSS variables: |
| 92 | +- `--atomic-rating-icon-active-color`: Color for filled/active icons |
| 93 | +- `--atomic-rating-icon-inactive-color`: Color for unfilled/inactive icons |
| 94 | + |
| 95 | +### Tab-Based Display |
| 96 | + |
| 97 | +Control which tabs display the facet: |
| 98 | + |
| 99 | +```html |
| 100 | +<!-- Show only on specific tabs --> |
| 101 | +<atomic-rating-range-facet |
| 102 | + field="rating" |
| 103 | + tabs-included='["reviews", "products"]'> |
| 104 | +</atomic-rating-range-facet> |
| 105 | + |
| 106 | +<!-- Hide on specific tabs --> |
| 107 | +<atomic-rating-range-facet |
| 108 | + field="rating" |
| 109 | + tabs-excluded='["documentation"]'> |
| 110 | +</atomic-rating-range-facet> |
| 111 | +``` |
| 112 | + |
| 113 | +### Conditional Facets (depends-on) |
| 114 | + |
| 115 | +Display the facet only when specific values are selected in other facets: |
| 116 | + |
| 117 | +```html |
| 118 | +<atomic-facet facet-id="producttype" field="producttype"></atomic-facet> |
| 119 | + |
| 120 | +<!-- Show rating facet only when "Electronics" is selected --> |
| 121 | +<atomic-rating-range-facet |
| 122 | + field="rating" |
| 123 | + depends-on-producttype="Electronics"> |
| 124 | +</atomic-rating-range-facet> |
| 125 | +``` |
| 126 | + |
| 127 | +## Accessibility |
| 128 | + |
| 129 | +The component is built with accessibility in mind: |
| 130 | +- Proper ARIA labels for screen readers |
| 131 | +- Keyboard navigation support |
| 132 | +- Focus management for improved usability |
| 133 | +- High-contrast mode support |
| 134 | + |
| 135 | +## Performance Considerations |
| 136 | + |
| 137 | +Use `injection-depth` to control how many results are scanned when generating facet values. Higher values provide more accurate facet counts but may impact performance: |
| 138 | + |
| 139 | +```html |
| 140 | +<atomic-rating-range-facet |
| 141 | + field="rating" |
| 142 | + injection-depth="2000"> |
| 143 | +</atomic-rating-range-facet> |
| 144 | +``` |
| 145 | + |
| 146 | +Default: 1000. Minimum: 0. |
| 147 | + |
| 148 | +</AtomicDocTemplate> |
0 commit comments