Skip to content

Commit

Permalink
Fix primefaces#2052: Accordion dynamic showcase example
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Oct 24, 2023
1 parent 707f85b commit 69e8e4b
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 0 deletions.
153 changes: 153 additions & 0 deletions components/doc/accordion/dynamicdoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { useState } from 'react';
import { Accordion, AccordionTab } from '../../lib/accordion/Accordion';
import { DocSectionCode } from '../common/docsectioncode';
import { DocSectionText } from '../common/docsectiontext';

export function DynamicDoc(props) {
const [tabs] = useState([
{
header: 'Dynamic I',
children: (
<p className="m-0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
)
},
{
header: 'Dynamic II',
children: (
<p className="m-0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
)
},
{
header: 'Dynamic III',
disabled: true
}
]);

const createDynamicTabs = () => {
return tabs.map((tab, i) => {
return (
<AccordionTab key={tab.header} header={tab.header} disabled={tab.disabled}>
{tab.children}
</AccordionTab>
);
});
};

const code = {
basic: `
<Accordion>{createDynamicTabs()}</Accordion>
`,
javascript: `
import React, { useState } from 'react';
import { Accordion, AccordionTab } from 'primereact/accordion';
export default function DynamicDemo() {
const [tabs] = useState([
{
header: 'Dynamic I',
children: (
<p className="m-0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
)
},
{
header: 'Dynamic II',
children: (
<p className="m-0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
)
},
{
header: 'Dynamic III',
disabled: true
}
]);
const createDynamicTabs = () => {
return tabs.map((tab, i) => {
return (
<AccordionTab key={tab.header} header={tab.header} disabled={tab.disabled}>
{tab.children}
</AccordionTab>
);
});
};
return (
<div className="card">
<Accordion>{createDynamicTabs()}</Accordion>
</div>
)
}
`,
typescript: `
import React, { useState } from 'react';
import { Accordion, AccordionTab } from 'primereact/accordion';
export default function DynamicDemo() {
const [tabs] = useState([
{
header: 'Dynamic I',
children: (
<p className="m-0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
)
},
{
header: 'Dynamic II',
children: (
<p className="m-0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
)
},
{
header: 'Dynamic III',
disabled: true
}
]);
const createDynamicTabs = () => {
return tabs.map((tab, i) => {
return (
<AccordionTab key={tab.header} header={tab.header} disabled={tab.disabled}>
{tab.children}
</AccordionTab>
);
});
};
return (
<div className="card">
<Accordion>{createDynamicTabs()}</Accordion>
</div>
)
}
`
};

return (
<>
<DocSectionText {...props}>
<p>Accordion tabs can be generated dynamically using code.</p>
</DocSectionText>
<div className="card">
<Accordion>{createDynamicTabs()}</Accordion>
</div>
<DocSectionCode code={code} />
</>
);
}
6 changes: 6 additions & 0 deletions pages/accordion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AccessibilityDoc } from '../../components/doc/accordion/accessibilitydo
import { BasicDoc } from '../../components/doc/accordion/basicdoc';
import { ControlledDoc } from '../../components/doc/accordion/controlleddoc';
import { DisabledDoc } from '../../components/doc/accordion/disableddoc';
import { DynamicDoc } from '../../components/doc/accordion/dynamicdoc';
import { ImportDoc } from '../../components/doc/accordion/importdoc';
import { MultipleDoc } from '../../components/doc/accordion/multipledoc';
import { PTDoc } from '../../components/doc/accordion/pt/ptdoc';
Expand Down Expand Up @@ -30,6 +31,11 @@ const AccordionDemo = () => {
label: 'Multiple',
component: MultipleDoc
},
{
id: 'dynamic',
label: 'Dynamic',
component: DynamicDoc
},
{
id: 'disabled',
label: 'Disabled',
Expand Down

0 comments on commit 69e8e4b

Please sign in to comment.