Skip to content

Commit

Permalink
fix code examples for accordion and accordion group
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhuignoto committed Apr 27, 2023
1 parent 296033b commit d30cff5
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
}
}

@media (min-width: 1600px) {
.rc-demo-code-block {
// width: 850px;
}
}

.rc-demo-code-copy-btn {
align-items: center;
background-color: var(--rc-tertiary-color-hex);
Expand Down
110 changes: 110 additions & 0 deletions packages/documentation/components/accordion-group/code-strings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
const text = `
<p>
Aenean aliquam dignissim pretium. Ut nulla nunc, euismod sit amet justo
vel, convallis volutpat neque. Morbi semper odio sed diam tristique, nec
tempor neque tempus. Praesent quis ultrices odio. Nulla vestibulum nulla
sed massa molestie, quis vulputate risus semper. Phasellus elementum,
metus in iaculis sollicitudin, risus elit pulvinar neque, eget pulvinar
odio libero eu mi. Vivamus id leo facilisis, tincidunt lacus semper,
condimentum est. Nam euismod non eros a lacinia.
</p>
`;

export const AutoClosing = `const App = () => {
return (
<AccordionGroup
titles={['one', 'two', 'three']}
autoClose
border={false}
size="sm"
>
${text.repeat(3)}
</AccordionGroup>
);
`;

export const CustomIconCode = `const App = () => {
return (
<AccordionGroup
titles={['one', 'two', 'three', 'four']}
border={false}
iconType="plus"
>
${text.repeat(4)}
</AccordionGroup>
);
`;

export const RTLCode = `const App = () => {
return (
<AccordionGroup
titles={['one', 'two', 'three', 'four']}
border
alignIconRight
>
${text.repeat(4)}
</AccordionGroup>
)
}`;

export const MediumSizedCode = `const App = () => {
return (
<AccordionGroup
titles={['one', 'two', 'three', 'four']}
border={false}
size="md"
>
${text.repeat(4)}
</AccordionGroup>
)
}`;

export const LargeSizedCode = `const App = () => {
return (
<AccordionGroup
titles={['one', 'two', 'three', 'four']}
border={false}
size="lg"
>
${text.repeat(4)}
</AccordionGroup>
)
}`;

export const DefaultCode = `const App = () => {
return (
<AccordionGroup titles={['one', 'two']}>
${text}
<div
style={{
height: '400px',
width: '100%',
}}
>
<Image src="https://bit.ly/3i9PcxC"></Image>
</div>
</AccordionGroup>
);
}`;

export const InitialStateCode = `const App = () => {
return (
<AccordionGroup
titles={['one', 'two']}
autoClose={false}
border={false}
expanded
focusable
>
${text}
<div
style={{
height: '300px',
width: '100%',
}}
>
<Image src="https://bit.ly/3i9PcxC"></Image>
</div>
</AccordionGroup>
);
}`;
47 changes: 40 additions & 7 deletions packages/documentation/components/accordion-group/widgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { useLayoutEffect, useState } from 'react';
import { Section, Text } from '../../../lib/components';
import { DemoWidget } from '../../common/demo-widget';
import useMedia from '../../common/useMedia';
import {
AutoClosing,
CustomIconCode,
DefaultCode,
InitialStateCode,
LargeSizedCode,
MediumSizedCode,
RTLCode,
} from './code-strings';
import {
AutoClosingSections,
CustomIcon,
Expand Down Expand Up @@ -37,7 +46,11 @@ function Widgets() {
return width > 0 ? (
<div className="rc-demo-widgets" style={{ minHeight: '1200px' }}>
<Section size="md" title="Default">
<DemoWidget name="AccordionGroup" width={width}>
<DemoWidget
name="AccordionGroup"
width={width}
codeString={DefaultCode}
>
{Default}
</DemoWidget>
</Section>
Expand All @@ -47,7 +60,11 @@ function Widgets() {
you want to keep the accordions closed or open on load. The example
shows the accordions open on load
</Text>
<DemoWidget name="AccordionGroup" width={width}>
<DemoWidget
name="AccordionGroup"
width={width}
codeString={InitialStateCode}
>
{InitialState}
</DemoWidget>
</Section>
Expand All @@ -56,7 +73,11 @@ function Widgets() {
The AccordionGroup can be configured to close all other sections when
one is open.
</Text>
<DemoWidget name="AccordionGroup" width={width}>
<DemoWidget
name="AccordionGroup"
width={width}
codeString={AutoClosing}
>
{AutoClosingSections}
</DemoWidget>
</Section>
Expand All @@ -65,20 +86,32 @@ function Widgets() {
The AccordionGroup can be configured to use custom icons and the
alignment of the icon can be changed.
</Text>
<DemoWidget name="AccordionGroup" width={width}>
<DemoWidget
name="AccordionGroup"
width={width}
codeString={CustomIconCode}
>
{CustomIcon}
</DemoWidget>
</Section>
<Section size="md" title="RTL">
<DemoWidget name="AccordionGroup" width={width}>
<DemoWidget name="AccordionGroup" width={width} codeString={RTLCode}>
{RTL}
</DemoWidget>
</Section>
<Section size="md" title="Custom Sizes">
<DemoWidget name="AccordionGroup" width={width}>
<DemoWidget
name="AccordionGroup"
width={width}
codeString={MediumSizedCode}
>
{MediumSized}
</DemoWidget>
<DemoWidget name="AccordionGroup" width={width}>
<DemoWidget
name="AccordionGroup"
width={width}
codeString={LargeSizedCode}
>
{LargeSized}
</DemoWidget>
</Section>
Expand Down
76 changes: 76 additions & 0 deletions packages/documentation/components/accordion/code-strings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const TextContent = `
<div>
<p>
Sed laoreet neque eget sem varius, et interdum dui venenatis.
Suspendisse in faucibus tortor, nec aliquet arcu. Quisque at Proin
auctor velit massa, euismod pretium dui euismod in. Pellentesque rhoncus
eros id posuere tincidunt. Maecenas quis libero vitae elit consectetur
finibus et ac libero. Donec at fermentum lectus. Cras iaculis augue non
mauris interdum, vitae pretium mi blandit. Aenean ultrices pellentesque
lectus ac faucibus. Morbi tristique vulputate nisi, id porttitor diam
egestas a. Suspendisse a tortor suscipit, accumsan massa at, viverra
urna. Maecenas vel lectus sodales, dapibus dolor eget, pharetra neque.
Nam eleifend id mauris in suscipit. Ut sed risus at mi vulputate
rhoncus.
</p>
<p>
It is a long established fact that a reader will be distracted by the
readable content of a page when looking at its layout. The point of
using Lorem Ipsum is that it has a more-or-less normal distribution of
letters, as opposed to using Content here, content here, making it look
like readable English. Many desktop publishing packages and web page
editors now use Lorem Ipsum as their default model text, and a search
for lorem ipsum will uncover many web sites still in their infancy.
Various versions have evolved over the years, sometimes by accident,
sometimes on purpose (injected humour and the like).
</p>
</div>
`;

export const DefaultCodeString = `const App = () => {
return (
<Accordion title="Lorem Ipsum" focusable>
${TextContent}
</Accordion>
);
}`;

export const RTLCodeString = `const App = () => {
return (
<Accordion title="Lorem Ipsum" alignIconRight border>
${TextContent}
</Accordion>
);
}`;

export const ExpandedCodeString = `const App = () => {
return (
<Accordion title="Lorem Ipsum" expanded focusable>
${TextContent}
</Accordion>
);
}`;

export const MediumSizedCodeString = `const App = () => {
return (
<Accordion title="Lorem Ipsum" size="md">
${TextContent}
</Accordion>
);
}`;

export const LargeSizedCodeString = `const App = () => {
return (
<Accordion title="Lorem Ipsum" size="lg">
${TextContent}
</Accordion>
);
}`;

export const CustomIconCodeString = `const App = () => {
return (
<Accordion title="Lorem Ipsum" customIcon={<span role="img">🔥</span>}>
${TextContent}
</Accordion>
);
}`;
40 changes: 34 additions & 6 deletions packages/documentation/components/accordion/widgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import { useEffect, useState } from 'react';
import { Section, Text } from '../../../lib/components';
import { DemoWidget } from '../../common/demo-widget';
import useMedia from '../../common/useMedia';
import {
CustomIconCodeString,
DefaultCodeString,
ExpandedCodeString,
LargeSizedCodeString,
MediumSizedCodeString,
RTLCodeString,
} from './code-strings';
import {
CustomIcon,
Default,
Expand Down Expand Up @@ -36,13 +44,17 @@ function Widgets() {
return width > 0 ? (
<div style={{ minHeight: '1200px' }} className="rc-demo-widgets">
<Section size="md" title="Default">
<DemoWidget width={width} name="Accordion" showCodeByDefault>
<DemoWidget
width={width}
name="Accordion"
codeString={DefaultCodeString}
>
{Default}
</DemoWidget>
</Section>
<Section size="md" title="RTL">
{/* <Text>The icon can be aligned to the right</Text> */}
<DemoWidget width={width} name="Accordion" showCodeByDefault>
<DemoWidget width={width} name="Accordion" codeString={RTLCodeString}>
{RTL}
</DemoWidget>
</Section>
Expand All @@ -51,20 +63,36 @@ function Widgets() {
Accordions can be expanded or collapsed by default. The example shows
a accordion expanded by default.
</Text>
<DemoWidget width={width} name="Accordion" showCodeByDefault>
<DemoWidget
width={width}
name="Accordion"
codeString={ExpandedCodeString}
>
{Expanded}
</DemoWidget>
</Section>
<Section>
<DemoWidget width={width} name="Accordion" showCodeByDefault>
<DemoWidget
width={width}
name="Accordion"
codeString={CustomIconCodeString}
>
{CustomIcon}
</DemoWidget>
</Section>
<Section size="md" title="Custom sizes">
<DemoWidget width={width} name="Accordion" showCodeByDefault>
<DemoWidget
width={width}
name="Accordion"
codeString={MediumSizedCodeString}
>
{MediumSized}
</DemoWidget>
<DemoWidget width={width} name="Accordion" showCodeByDefault>
<DemoWidget
width={width}
name="Accordion"
codeString={LargeSizedCodeString}
>
{LargeSized}
</DemoWidget>
</Section>
Expand Down
17 changes: 16 additions & 1 deletion packages/documentation/components/auto-suggest/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import DemoPageRenderer from '../../common/demo-page-renderer';
import Widgets from './widgets';

const Description = (
<div>
<p>
An Autosuggest UI Component is a type of user interface element that
provides users with a list of suggested words or phrases as they type. It
is designed to provide users with a more efficient and convenient way to
search for information by quickly narrowing down the results list.
</p>
<p>
Autosuggest UI components can be used in a variety of applications, such
as web search engines, online dictionaries, and documentation sites.
</p>
</div>
);

function index() {
return (
<DemoPageRenderer
title="Auto Suggest"
description="Auto Suggest is a component that allows the user to type in a value and get a list of suggestions. The user can then select a suggestion from the list."
description={Description}
stackBlitzCodes={['react-ts-hf5mto']}
pageIcon={<FontAwesomeIcon icon={faMagic} size="2x" />}
sourceId="auto-suggest/auto-suggest.tsx"
Expand Down
Loading

1 comment on commit d30cff5

@vercel
Copy link

@vercel vercel bot commented on d30cff5 Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.