Skip to content

Enhance ContentItem component with flexed layout option and update Picker API #3633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docuilib/src/assets/icons/chevronDown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docuilib/src/assets/icons/star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion docuilib/src/components/pageComponents/ContentItem.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@

.blocker {
pointer-events: none;

&.flexed {
width: 100%;
height: 100%;
padding: 20px;
}

// Note: Extends button's (Touchable) container to match its parent width
button {
width: inherit;
}
}

.componentExample {
Expand All @@ -34,4 +45,4 @@
display: flex;
justify-content: center;
align-items: center;
}
}
37 changes: 21 additions & 16 deletions docuilib/src/components/pageComponents/ContentItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import CodeIcon from '../../assets/icons/code';
type ComponentItemProps = {
componentName: string;
props?: Record<string, unknown> | Record<string, unknown>[];
snippet?: string
snippet?: string;
flexed?: boolean;
showCodeButton?: boolean;
};

Expand All @@ -33,7 +34,7 @@ function generateComponentCodeSnippet(componentName: string, componentProps: Rec
}

const ComponentItem = (props: ComponentItemProps) => {
const {componentName, props: componentProps, snippet, showCodeButton = false} = props;
const {componentName, props: componentProps, snippet, flexed, showCodeButton = false} = props;
const [showCode, setShowCode] = useState(false);

const code = useMemo(() => {
Expand All @@ -54,9 +55,9 @@ const ComponentItem = (props: ComponentItemProps) => {
}, []);

const componentPreview = (
<div className={styles.blocker}>
<div className={`${styles.blocker} ${flexed ? styles.flexed : ''}`}>
<LiveProvider code={code} scope={ReactLiveScope}>
<LivePreview/>
<LivePreview style={{width: '100%'}}/>
</LiveProvider>
</div>
);
Expand Down Expand Up @@ -84,22 +85,16 @@ type Item = {
value?: any;
snippet?: string;
height?: number;
flexed?: boolean;
};
type ContentItemProps = {
item: Item;
componentName: string;
showCodeButton?: boolean;
category: string;
};

const extractComponentFromSnippet = (snippet: string) => {
if (!snippet.startsWith('<')) {
return;
}
const firstWord = snippet.split(' ')[0];
return firstWord.slice(1);
};

export const ContentItem = ({item, componentName, showCodeButton}: ContentItemProps) => {
export const ContentItem = ({item, componentName, showCodeButton, category}: ContentItemProps) => {
const getFigmaEmbed = (value: string, height = 450) => {
const modifiedValue = !value.includes('page-selector=') ? value + '&page-selector=false' : value;
return <iframe width={'100%'} height={height} src={modifiedValue}/>;
Expand All @@ -116,12 +111,22 @@ export const ContentItem = ({item, componentName, showCodeButton}: ContentItemPr
const value = item.value;

if (item.props || item.snippet) {
const name = item.snippet ? extractComponentFromSnippet(item.snippet) : item.component ?? componentName;
const isComponentExists = !!(_.get(ReactLiveScope, name));
let name = item.component ?? componentName;
if (category === 'incubator') {
name = `Incubator.${name}`;
}

const isComponentExists = !!_.get(ReactLiveScope, name);

if (isComponentExists) {
return (
<ComponentItem componentName={name} props={item.props} snippet={item.snippet} showCodeButton={showCodeButton}/>
<ComponentItem
componentName={name}
props={item.props}
snippet={item.snippet}
showCodeButton={showCodeButton}
flexed={item.flexed}
/>
);
} else if (!value) {
return <div style={{color: 'red'}}>Component Not Supported</div>;
Expand Down
10 changes: 9 additions & 1 deletion docuilib/src/components/pageComponents/SectionContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ export const SectionContent = ({section, component}) => {
{_.map(content, (item, index: number) => {
const isLast = index === content.length - 1;

return <div style={{marginBottom: isLast ? 0 : 40, border: '1px solid #F8F9FA', background: item.background}}><ContentItem item={item} componentName={component.name}/></div>;
return (
<div style={{marginBottom: isLast ? 0 : 40, border: '1px solid #F8F9FA', background: item.background}}>
<ContentItem
item={item}
componentName={component.name}
category={component.category}
/>
</div>
);
})}
</div>
);
Expand Down
7 changes: 6 additions & 1 deletion docuilib/src/components/pageComponents/TableSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ export const TableSection = ({section, component}) => {
if (index < numberOfColumns - 1) {
return (
<td style={{backgroundColor: item.background || 'white', padding: 0, height: '100px'}}>
<ContentItem item={item} componentName={component.name} showCodeButton/>
<ContentItem
item={item}
componentName={component.name}
showCodeButton
category={component.category}
/>
</td>
);
}
Expand Down
10 changes: 10 additions & 0 deletions docuilib/src/theme/ReactLiveScope/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ Assets.loadAssetsGroup('icons.demo', {
width: 24,
height: 24
},
chevronDown: {
uri: require('../../assets/icons/chevronDown.png').default,
width: 14,
height: 8
},
star: {
uri: require('../../assets/icons/star.png').default,
width: 24,
height: 24
},
// add: require('../../assets/icons/add.png').default,
// camera: require('../../assets/icons/cameraSelected.png').default,
// close: require('../../assets/icons/close.png').default,
Expand Down
Loading