|
| 1 | +import React from 'react'; |
| 2 | +import { IconHelp } from '../../src/lib/components/iconhelper/IconHelper'; |
| 3 | +import { Text } from '../../src/lib/components/text/Text.component'; |
| 4 | +import { Stack } from '../../src/lib/spacing'; |
| 5 | +import { Wrapper } from '../common'; |
| 6 | + |
| 7 | +export default { |
| 8 | + title: 'Components/IconHelp', |
| 9 | + component: IconHelp, |
| 10 | + decorators: [(story: () => React.ReactNode) => <Wrapper>{story()}</Wrapper>], |
| 11 | +}; |
| 12 | + |
| 13 | +export const Simple = { |
| 14 | + name: 'Simple', |
| 15 | + render: () => ( |
| 16 | + <Stack direction="horizontal" gap="r4"> |
| 17 | + <Text>Replication policy</Text> |
| 18 | + <IconHelp |
| 19 | + tooltipMessage="Defines how objects are replicated across locations." |
| 20 | + aria-label="More info about replication policy" |
| 21 | + /> |
| 22 | + </Stack> |
| 23 | + ), |
| 24 | +}; |
| 25 | + |
| 26 | +export const WithPlacement = { |
| 27 | + name: 'Tooltip placement', |
| 28 | + render: () => ( |
| 29 | + <Stack direction="vertical" gap="r24"> |
| 30 | + <Stack direction="horizontal" gap="r4"> |
| 31 | + <Text> |
| 32 | + Placement <b>top</b> |
| 33 | + </Text> |
| 34 | + <IconHelp |
| 35 | + placement="top" |
| 36 | + tooltipMessage="Appears above the icon." |
| 37 | + aria-label="Top tooltip" |
| 38 | + /> |
| 39 | + </Stack> |
| 40 | + <Stack direction="horizontal" gap="r4"> |
| 41 | + <Text> |
| 42 | + Placement <b>right</b> (default) |
| 43 | + </Text> |
| 44 | + <IconHelp |
| 45 | + placement="right" |
| 46 | + tooltipMessage="Appears to the right of the icon." |
| 47 | + aria-label="Right tooltip" |
| 48 | + /> |
| 49 | + </Stack> |
| 50 | + <Stack direction="horizontal" gap="r4"> |
| 51 | + <Text> |
| 52 | + Placement <b>bottom</b> |
| 53 | + </Text> |
| 54 | + <IconHelp |
| 55 | + placement="bottom" |
| 56 | + tooltipMessage="Appears below the icon." |
| 57 | + aria-label="Bottom tooltip" |
| 58 | + /> |
| 59 | + </Stack> |
| 60 | + <Stack direction="horizontal" gap="r4"> |
| 61 | + <Text> |
| 62 | + Placement <b>left</b> |
| 63 | + </Text> |
| 64 | + <IconHelp |
| 65 | + placement="left" |
| 66 | + tooltipMessage="Appears to the left of the icon." |
| 67 | + aria-label="Left tooltip" |
| 68 | + /> |
| 69 | + </Stack> |
| 70 | + </Stack> |
| 71 | + ), |
| 72 | +}; |
| 73 | + |
| 74 | +const KeyValueRow = ({ |
| 75 | + label, |
| 76 | + labelHelp, |
| 77 | + labelAriaLabel, |
| 78 | + value, |
| 79 | + helpMessage, |
| 80 | + helpAriaLabel, |
| 81 | +}: { |
| 82 | + label: string; |
| 83 | + labelHelp?: React.ReactNode; |
| 84 | + labelAriaLabel?: string; |
| 85 | + value: React.ReactNode; |
| 86 | + helpMessage?: React.ReactNode; |
| 87 | + helpAriaLabel?: string; |
| 88 | +}) => ( |
| 89 | + <div |
| 90 | + style={{ |
| 91 | + display: 'grid', |
| 92 | + gridTemplateColumns: '220px 1fr', |
| 93 | + alignItems: 'baseline', |
| 94 | + gap: '16px', |
| 95 | + padding: '6px 0', |
| 96 | + }} |
| 97 | + > |
| 98 | + <Stack direction="horizontal" gap="r4"> |
| 99 | + <Text color="textSecondary">{label}</Text> |
| 100 | + {labelHelp && ( |
| 101 | + <IconHelp |
| 102 | + tooltipMessage={labelHelp} |
| 103 | + aria-label={labelAriaLabel ?? `More info about ${label}`} |
| 104 | + /> |
| 105 | + )} |
| 106 | + </Stack> |
| 107 | + <Stack direction="horizontal" gap="r4"> |
| 108 | + <Text>{value}</Text> |
| 109 | + {helpMessage && ( |
| 110 | + <IconHelp |
| 111 | + tooltipMessage={helpMessage} |
| 112 | + aria-label={helpAriaLabel ?? `More info about ${label} value`} |
| 113 | + /> |
| 114 | + )} |
| 115 | + </Stack> |
| 116 | + </div> |
| 117 | +); |
| 118 | + |
| 119 | +export const InKeyValueList = { |
| 120 | + name: 'Explaining keys and values', |
| 121 | + render: () => ( |
| 122 | + <div style={{ maxWidth: 620 }}> |
| 123 | + <KeyValueRow label="Bucket name" value="prod-customer-assets" /> |
| 124 | + <KeyValueRow |
| 125 | + label="Object lock" |
| 126 | + labelHelp="Object lock prevents objects from being deleted or overwritten for a fixed amount of time." |
| 127 | + value="Governance" |
| 128 | + helpMessage="Governance mode allows privileged users to change retention; Compliance mode does not." |
| 129 | + /> |
| 130 | + <KeyValueRow |
| 131 | + label="RPO" |
| 132 | + labelHelp="Recovery Point Objective — the maximum acceptable amount of data loss measured in time." |
| 133 | + value="15 minutes" |
| 134 | + /> |
| 135 | + <KeyValueRow |
| 136 | + label="Storage class" |
| 137 | + value="Standard" |
| 138 | + helpMessage="Affects durability, latency and pricing of stored objects." |
| 139 | + /> |
| 140 | + <KeyValueRow label="Region" value="us-east-1" /> |
| 141 | + </div> |
| 142 | + ), |
| 143 | +}; |
0 commit comments