|
| 1 | +# Suggestion Card |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +#### [View on MongoDB.design](https://www.mongodb.design/component/suggestions/live-example/) |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +### PNPM |
| 10 | + |
| 11 | +```shell |
| 12 | +pnpm add @lg-chat/suggestions |
| 13 | +``` |
| 14 | + |
| 15 | +### Yarn |
| 16 | + |
| 17 | +```shell |
| 18 | +yarn add @lg-chat/suggestions |
| 19 | +``` |
| 20 | + |
| 21 | +### NPM |
| 22 | + |
| 23 | +```shell |
| 24 | +npm install @lg-chat/suggestions |
| 25 | +``` |
| 26 | + |
| 27 | +## Example |
| 28 | + |
| 29 | +```tsx |
| 30 | +import { SuggestedActions, State } from '@lg-chat/suggestions'; |
| 31 | + |
| 32 | +const configurationParameters = [ |
| 33 | + { key: 'Cluster Tier', value: 'M10 ($9.00/month)' }, |
| 34 | + { key: 'Provider', value: 'AWS / N. Virginia (us-east-1)' }, |
| 35 | + { key: 'Storage', value: '10 GB' }, |
| 36 | + { key: 'RAM', value: '2 GB' }, |
| 37 | + { key: 'vCPUs', value: '2 vCPUs' }, |
| 38 | +]; |
| 39 | + |
| 40 | +// Basic suggestion card with apply button |
| 41 | +<SuggestedActions |
| 42 | + state={State.Unset} |
| 43 | + configurationParameters={configurationParameters} |
| 44 | + onClickApply={() => console.log('Apply clicked')} |
| 45 | +/> |
| 46 | + |
| 47 | +// Success state with applied parameters |
| 48 | +<SuggestedActions |
| 49 | + state={State.Success} |
| 50 | + configurationParameters={[ |
| 51 | + { key: 'Cluster Tier', value: 'M10 ($9.00/month)' }, |
| 52 | + { key: 'Provider', value: 'AWS / N. Virginia (us-east-1)' }, |
| 53 | + { key: 'Cloud Provider & Region', value: 'AWS / N. Virginia (us-east-1)', state: State.Success }, |
| 54 | + { key: 'Cluster Tier', value: 'M10 ($9.00/month)', state: State.Success }, |
| 55 | + ]} |
| 56 | + onClickApply={() => console.log('Apply clicked')} |
| 57 | +/> |
| 58 | + |
| 59 | +// Error state with failed parameters |
| 60 | +<SuggestedActions |
| 61 | + state={State.Error} |
| 62 | + configurationParameters={[ |
| 63 | + { key: 'Cluster Tier', value: 'M30 ($31.00/month)' }, |
| 64 | + { key: 'Provider', value: 'GCP / Iowa (us-central1)' }, |
| 65 | + { key: 'Cloud Provider & Region', value: 'GCP / Iowa (us-central1)', state: State.Error }, |
| 66 | + { key: 'Cluster Tier', value: 'M30 ($31.00/month)', state: State.Error }, |
| 67 | + ]} |
| 68 | + onClickApply={() => console.log('Apply clicked')} |
| 69 | +/> |
| 70 | +``` |
| 71 | + |
| 72 | +## State Types |
| 73 | + |
| 74 | +The `State` enum provides the following options: |
| 75 | + |
| 76 | +| State | Value | Description | |
| 77 | +| --------- | ----------- | ------------------------------------------------------ | |
| 78 | +| `Unset` | `'unset'` | Shows configuration suggestions with an "Apply" button | |
| 79 | +| `Success` | `'success'` | Shows success banner with applied parameters | |
| 80 | +| `Error` | `'error'` | Shows error banner with failed parameters | |
| 81 | + |
| 82 | +## Configuration Parameters |
| 83 | + |
| 84 | +Each configuration parameter is an object with the following structure: |
| 85 | + |
| 86 | +```tsx |
| 87 | +interface ConfigurationParameter { |
| 88 | + key: string; // The parameter name |
| 89 | + value: string; // The parameter value |
| 90 | + state?: State; // The parameter state (defaults to 'unset') |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +The component automatically filters and displays parameters based on their state: |
| 95 | + |
| 96 | +- **Table**: Shows parameters with `unset` state (or no state) |
| 97 | +- **Success Banner**: Shows parameters with `success` state |
| 98 | +- **Error Banner**: Shows parameters with `error` state |
| 99 | + |
| 100 | +## Properties |
| 101 | + |
| 102 | +| Prop | Type | Description | Default | |
| 103 | +| ------------------------- | ------------------------- | -------------------------------------------------------------------------------------------- | ------- | |
| 104 | +| `state` | `State` | Determines the current state and rendering behavior of the suggestion card | | |
| 105 | +| `configurationParameters` | `ConfigurationParameters` | Array of configuration parameters, each with key, value, and optional state | | |
| 106 | +| `onClickApply` | `() => void` | Callback fired when the user clicks the "Apply" button (shown when `state` is `State.Unset`) | | |
| 107 | +| `darkMode` | `boolean` | Determines if the component is rendered in dark mode | `false` | |
| 108 | +| `...` | `HTMLElementProps<'div'>` | Props spread on root element | | |
0 commit comments