|
| 1 | +import figma from '@figma/code-connect'; |
| 2 | +import { ExpandableSection, ExpandableSectionToggle, Stack, StackItem } from '@patternfly/react-core'; |
| 3 | + |
| 4 | +// TODO: DESIGN: This component needs to be overhauled. Using the base component approach present in |
| 5 | +// other components would significantly reduce complexity. |
| 6 | +// TODO: DESIGN: Create toggle component |
| 7 | +// onToggle={() => {}} // only required if the user wants to be able to have other side effects when opening/closing |
| 8 | +// isExpanded={() => {}} // only required if the user wants to be able to have other side effects when opening/closing |
| 9 | + |
| 10 | +// Documentation for ExpandableSection can be found at https://www.patternfly.org/components/expandable-section |
| 11 | + |
| 12 | +const customToggleContent = ` |
| 13 | + <div> |
| 14 | + <span>You can also use icons </span> |
| 15 | + <CheckCircleIcon /> |
| 16 | + <span> or badges </span> |
| 17 | + <Badge isRead={true}>4</Badge> |
| 18 | + <span> !</span> |
| 19 | + </div> |
| 20 | +`; |
| 21 | + |
| 22 | +figma.connect( |
| 23 | + ExpandableSection, |
| 24 | + 'https://www.figma.com/design/aEBBvq0J3EPXxHvv6WgDx9/PatternFly-6--Components-Test?node-id=2404-21', |
| 25 | + { |
| 26 | + props: { |
| 27 | + toggleText: figma.string('Toggle Text More') |
| 28 | + }, |
| 29 | + example: (props) => ( |
| 30 | + <ExpandableSection |
| 31 | + onToggle={() => {}} |
| 32 | + toggleText={isExpanded ? 'Show less basic example content' : `${props.toggleText}`} |
| 33 | + > |
| 34 | + This content is visible only when the component is expanded. |
| 35 | + </ExpandableSection> |
| 36 | + ) |
| 37 | + } |
| 38 | +); |
| 39 | + |
| 40 | +figma.connect( |
| 41 | + ExpandableSection, |
| 42 | + 'https://www.figma.com/design/aEBBvq0J3EPXxHvv6WgDx9/PatternFly-6--Components-Test?node-id=2404-21', |
| 43 | + { |
| 44 | + variant: { State: 'Expanded Basic' }, |
| 45 | + props: { |
| 46 | + // enum |
| 47 | + expandedContentSectionText: figma.string('Expanded Text'), |
| 48 | + toggleText: figma.string('Toggle Text Less') |
| 49 | + }, |
| 50 | + example: (props) => ( |
| 51 | + <ExpandableSection |
| 52 | + isExpanded |
| 53 | + onToggle={() => {}} |
| 54 | + toggleText={isExpanded ? `${props.toggleText}` : 'Show less basic example content'} |
| 55 | + > |
| 56 | + {props.expandedContentSectionText} |
| 57 | + </ExpandableSection> |
| 58 | + ) |
| 59 | + } |
| 60 | +); |
| 61 | + |
| 62 | +figma.connect( |
| 63 | + ExpandableSection, |
| 64 | + 'https://www.figma.com/design/aEBBvq0J3EPXxHvv6WgDx9/PatternFly-6--Components-Test?node-id=2404-21', |
| 65 | + { |
| 66 | + variant: { State: 'Expand Detached' }, |
| 67 | + props: { |
| 68 | + // enum |
| 69 | + expandedContentSectionText: figma.string('Expanded Text'), |
| 70 | + toggleText: figma.string('Toggle Text Less'), |
| 71 | + toggleId: 'toggle-id', |
| 72 | + contentId: 'content-id' |
| 73 | + }, |
| 74 | + example: (props) => ( |
| 75 | + <Stack hasGutter> |
| 76 | + <StackItem> |
| 77 | + <ExpandableSection isExpanded={false} isDetached toggleId={props.toggleId} contentId={props.contentId}> |
| 78 | + {props.expandedContentSectionText} |
| 79 | + </ExpandableSection> |
| 80 | + </StackItem> |
| 81 | + <StackItem> |
| 82 | + <ExpandableSectionToggle |
| 83 | + onToggle={() => {}} |
| 84 | + toggleId={props.toggleId} |
| 85 | + contentId={props.contentId} |
| 86 | + direction="up" |
| 87 | + > |
| 88 | + {isExpanded ? `${props.toggleText}` : 'Show less basic example content'} |
| 89 | + </ExpandableSectionToggle> |
| 90 | + </StackItem> |
| 91 | + </Stack> |
| 92 | + ) |
| 93 | + } |
| 94 | +); |
| 95 | + |
| 96 | +figma.connect( |
| 97 | + ExpandableSection, |
| 98 | + 'https://www.figma.com/design/aEBBvq0J3EPXxHvv6WgDx9/PatternFly-6--Components-Test?node-id=2404-21', |
| 99 | + { |
| 100 | + variant: { State: 'Expanded Indent' }, |
| 101 | + props: { |
| 102 | + // enum |
| 103 | + expandedContentSectionText: figma.string('Expanded Text'), |
| 104 | + toggleText: figma.string('Toggle Text Less'), |
| 105 | + toggleId: 'toggle-id', |
| 106 | + contentId: 'content-id' |
| 107 | + }, |
| 108 | + example: (props) => ( |
| 109 | + <ExpandableSection |
| 110 | + toggleText={isExpanded ? `${props.toggleText}` : 'Show less indented example content'} |
| 111 | + isExpanded={isExpanded} |
| 112 | + isIndented |
| 113 | + onToggle={() => {}} |
| 114 | + > |
| 115 | + {props.expandedContentSectionText} |
| 116 | + </ExpandableSection> |
| 117 | + ) |
| 118 | + } |
| 119 | +); |
| 120 | + |
| 121 | +figma.connect( |
| 122 | + ExpandableSection, |
| 123 | + 'https://www.figma.com/design/aEBBvq0J3EPXxHvv6WgDx9/PatternFly-6--Components-Test?node-id=2404-21', |
| 124 | + { |
| 125 | + variant: { State: 'Default Custom Content' }, |
| 126 | + example: () => ( |
| 127 | + <ExpandableSection toggleContent={customToggleContent} isExpanded={isExpanded} onToggle={() => {}}> |
| 128 | + This content is visible only when the component is expanded. |
| 129 | + </ExpandableSection> |
| 130 | + ) |
| 131 | + } |
| 132 | +); |
| 133 | + |
| 134 | +figma.connect( |
| 135 | + ExpandableSection, |
| 136 | + 'https://www.figma.com/design/aEBBvq0J3EPXxHvv6WgDx9/PatternFly-6--Components-Test?node-id=2404-21', |
| 137 | + { |
| 138 | + variant: { State: 'Expanded Custom Content' }, |
| 139 | + example: () => ( |
| 140 | + <ExpandableSection toggleContent={customToggleContent} isExpanded={isExpanded} onToggle={() => {}}> |
| 141 | + This content is visible only when the component is expanded. |
| 142 | + </ExpandableSection> |
| 143 | + ) |
| 144 | + } |
| 145 | +); |
| 146 | + |
| 147 | +figma.connect( |
| 148 | + ExpandableSection, |
| 149 | + 'https://www.figma.com/design/aEBBvq0J3EPXxHvv6WgDx9/PatternFly-6--Components-Test?node-id=2404-21', |
| 150 | + { |
| 151 | + variant: { State: 'Expanded Custom with Component swap' }, |
| 152 | + example: () => ( |
| 153 | + <ExpandableSection toggleContent={customToggleContent} isExpanded={isExpanded} onToggle={() => {}}> |
| 154 | + This content is visible only when the component is expanded. |
| 155 | + </ExpandableSection> |
| 156 | + ) |
| 157 | + } |
| 158 | +); |
0 commit comments