|
| 1 | +import React, { useState } from 'react' |
| 2 | +import { |
| 3 | + CCard, |
| 4 | + CCardBody, |
| 5 | + CCardHeader, |
| 6 | + CCol, |
| 7 | + CRow, |
| 8 | + CAccordion, |
| 9 | + CAccordionBody, |
| 10 | + CAccordionButton, |
| 11 | + CAccordionCollapse, |
| 12 | + CAccordionHeader, |
| 13 | + CAccordionItem, |
| 14 | +} from '@coreui/react' |
| 15 | +import { DocsLink, Example } from 'src/reusable' |
| 16 | + |
| 17 | +const Accordion = () => { |
| 18 | + const [activeKey, setActiveKey] = useState(0) |
| 19 | + const [activeKey2, setActiveKey2] = useState(0) |
| 20 | + |
| 21 | + return ( |
| 22 | + <CRow> |
| 23 | + <CCol> |
| 24 | + <CCard className="mb-4"> |
| 25 | + <CCardHeader> |
| 26 | + <strong>React Accordion</strong> |
| 27 | + </CCardHeader> |
| 28 | + <CCardBody> |
| 29 | + <p class="text-medium-emphasis small"> |
| 30 | + Click the accordions below to expand/collapse the accordion content. |
| 31 | + </p> |
| 32 | + <Example href="https://coreui.io/react/docs/4.0/components/accordion"> |
| 33 | + <CAccordion> |
| 34 | + <CAccordionItem> |
| 35 | + <CAccordionHeader> |
| 36 | + <CAccordionButton |
| 37 | + collapsed={activeKey !== 1} |
| 38 | + onClick={() => (activeKey === 1 ? setActiveKey(0) : setActiveKey(1))} |
| 39 | + > |
| 40 | + Accordion Item #1 |
| 41 | + </CAccordionButton> |
| 42 | + </CAccordionHeader> |
| 43 | + <CAccordionCollapse visible={activeKey === 1}> |
| 44 | + <CAccordionBody> |
| 45 | + <strong>This is the first item's accordion body.</strong> It is hidden by |
| 46 | + default, until the collapse plugin adds the appropriate classes that we use to |
| 47 | + style each element. These classes control the overall appearance, as well as |
| 48 | + the showing and hiding via CSS transitions. You can modify any of this with |
| 49 | + custom CSS or overriding our default variables. It's also worth noting that |
| 50 | + just about any HTML can go within the <code>.accordion-body</code>, though the |
| 51 | + transition does limit overflow. |
| 52 | + </CAccordionBody> |
| 53 | + </CAccordionCollapse> |
| 54 | + </CAccordionItem> |
| 55 | + <CAccordionItem> |
| 56 | + <CAccordionHeader> |
| 57 | + <CAccordionButton |
| 58 | + collapsed={activeKey !== 2} |
| 59 | + onClick={() => (activeKey === 2 ? setActiveKey(0) : setActiveKey(2))} |
| 60 | + > |
| 61 | + Accordion Item #2 |
| 62 | + </CAccordionButton> |
| 63 | + </CAccordionHeader> |
| 64 | + <CAccordionCollapse visible={activeKey === 2}> |
| 65 | + <CAccordionBody> |
| 66 | + <strong>This is the second item's accordion body.</strong> It is hidden by |
| 67 | + default, until the collapse plugin adds the appropriate classes that we use to |
| 68 | + style each element. These classes control the overall appearance, as well as |
| 69 | + the showing and hiding via CSS transitions. You can modify any of this with |
| 70 | + custom CSS or overriding our default variables. It's also worth noting that |
| 71 | + just about any HTML can go within the <code>.accordion-body</code>, though the |
| 72 | + transition does limit overflow. |
| 73 | + </CAccordionBody> |
| 74 | + </CAccordionCollapse> |
| 75 | + </CAccordionItem> |
| 76 | + <CAccordionItem> |
| 77 | + <CAccordionHeader> |
| 78 | + <CAccordionButton |
| 79 | + collapsed={activeKey !== 3} |
| 80 | + onClick={() => (activeKey === 3 ? setActiveKey(0) : setActiveKey(3))} |
| 81 | + > |
| 82 | + Accordion Item #3 |
| 83 | + </CAccordionButton> |
| 84 | + </CAccordionHeader> |
| 85 | + <CAccordionCollapse visible={activeKey === 3}> |
| 86 | + <CAccordionBody> |
| 87 | + <strong>This is the third item's accordion body.</strong> It is hidden by |
| 88 | + default, until the collapse plugin adds the appropriate classes that we use to |
| 89 | + style each element. These classes control the overall appearance, as well as |
| 90 | + the showing and hiding via CSS transitions. You can modify any of this with |
| 91 | + custom CSS or overriding our default variables. It's also worth noting that |
| 92 | + just about any HTML can go within the <code>.accordion-body</code>, though the |
| 93 | + transition does limit overflow. |
| 94 | + </CAccordionBody> |
| 95 | + </CAccordionCollapse> |
| 96 | + </CAccordionItem> |
| 97 | + </CAccordion> |
| 98 | + </Example> |
| 99 | + </CCardBody> |
| 100 | + </CCard> |
| 101 | + <CCard className="mb-4"> |
| 102 | + <CCardHeader> |
| 103 | + <strong>React Accordion</strong> <small>Flush</small> |
| 104 | + </CCardHeader> |
| 105 | + <CCardBody> |
| 106 | + <p class="text-medium-emphasis small"> |
| 107 | + Add <code class="css-0">flush</code> to remove the default{' '} |
| 108 | + <code class="css-0">background-color</code>, some borders, and some rounded corners to |
| 109 | + render accordions edge-to-edge with their parent container. |
| 110 | + </p> |
| 111 | + <Example href="https://coreui.io/react/docs/4.0/components/accordion"> |
| 112 | + <CAccordion flush> |
| 113 | + <CAccordionItem> |
| 114 | + <CAccordionHeader> |
| 115 | + <CAccordionButton |
| 116 | + collapsed={activeKey2 !== 1} |
| 117 | + onClick={() => (activeKey2 === 1 ? setActiveKey2(0) : setActiveKey2(1))} |
| 118 | + > |
| 119 | + Accordion Item #1 |
| 120 | + </CAccordionButton> |
| 121 | + </CAccordionHeader> |
| 122 | + <CAccordionCollapse visible={activeKey2 === 1}> |
| 123 | + <CAccordionBody> |
| 124 | + <strong>This is the first item's accordion body.</strong> It is hidden by |
| 125 | + default, until the collapse plugin adds the appropriate classes that we use to |
| 126 | + style each element. These classes control the overall appearance, as well as |
| 127 | + the showing and hiding via CSS transitions. You can modify any of this with |
| 128 | + custom CSS or overriding our default variables. It's also worth noting that |
| 129 | + just about any HTML can go within the <code>.accordion-body</code>, though the |
| 130 | + transition does limit overflow. |
| 131 | + </CAccordionBody> |
| 132 | + </CAccordionCollapse> |
| 133 | + </CAccordionItem> |
| 134 | + <CAccordionItem> |
| 135 | + <CAccordionHeader> |
| 136 | + <CAccordionButton |
| 137 | + collapsed={activeKey2 !== 2} |
| 138 | + onClick={() => (activeKey2 === 2 ? setActiveKey2(0) : setActiveKey2(2))} |
| 139 | + > |
| 140 | + Accordion Item #2 |
| 141 | + </CAccordionButton> |
| 142 | + </CAccordionHeader> |
| 143 | + <CAccordionCollapse visible={activeKey2 === 2}> |
| 144 | + <CAccordionBody> |
| 145 | + <strong>This is the second item's accordion body.</strong> It is hidden by |
| 146 | + default, until the collapse plugin adds the appropriate classes that we use to |
| 147 | + style each element. These classes control the overall appearance, as well as |
| 148 | + the showing and hiding via CSS transitions. You can modify any of this with |
| 149 | + custom CSS or overriding our default variables. It's also worth noting that |
| 150 | + just about any HTML can go within the <code>.accordion-body</code>, though the |
| 151 | + transition does limit overflow. |
| 152 | + </CAccordionBody> |
| 153 | + </CAccordionCollapse> |
| 154 | + </CAccordionItem> |
| 155 | + <CAccordionItem> |
| 156 | + <CAccordionHeader> |
| 157 | + <CAccordionButton |
| 158 | + collapsed={activeKey2 !== 3} |
| 159 | + onClick={() => (activeKey2 === 3 ? setActiveKey2(0) : setActiveKey2(3))} |
| 160 | + > |
| 161 | + Accordion Item #3 |
| 162 | + </CAccordionButton> |
| 163 | + </CAccordionHeader> |
| 164 | + <CAccordionCollapse visible={activeKey2 === 3}> |
| 165 | + <CAccordionBody> |
| 166 | + <strong>This is the third item's accordion body.</strong> It is hidden by |
| 167 | + default, until the collapse plugin adds the appropriate classes that we use to |
| 168 | + style each element. These classes control the overall appearance, as well as |
| 169 | + the showing and hiding via CSS transitions. You can modify any of this with |
| 170 | + custom CSS or overriding our default variables. It's also worth noting that |
| 171 | + just about any HTML can go within the <code>.accordion-body</code>, though the |
| 172 | + transition does limit overflow. |
| 173 | + </CAccordionBody> |
| 174 | + </CAccordionCollapse> |
| 175 | + </CAccordionItem> |
| 176 | + </CAccordion> |
| 177 | + </Example> |
| 178 | + </CCardBody> |
| 179 | + </CCard> |
| 180 | + </CCol> |
| 181 | + </CRow> |
| 182 | + ) |
| 183 | +} |
| 184 | + |
| 185 | +export default Accordion |
0 commit comments