Skip to content

Commit f874994

Browse files
authored
Enhance ContentItem component with flexed layout option and update Picker API (#3633)
* Enhance ContentItem component with flexed layout option and styling adjustments * Fix Incubator components rendering in docs * Refactor ContentItem component to use lodash for safer property access and simplify component name handling * Refactor ContentItem component to use category prop instead of isIncubator * Add star icon and update Picker example to use the new icon * Add chevronDown to Picker examples * Extend button container width to match parent in ContentItem styles * Update Picker example and remove wrapping View
1 parent 07b9a10 commit f874994

File tree

9 files changed

+445
-30
lines changed

9 files changed

+445
-30
lines changed
327 Bytes
Loading

docuilib/src/assets/icons/star.png

578 Bytes
Loading

docuilib/src/components/pageComponents/ContentItem.module.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212

1313
.blocker {
1414
pointer-events: none;
15+
16+
&.flexed {
17+
width: 100%;
18+
height: 100%;
19+
padding: 20px;
20+
}
21+
22+
// Note: Extends button's (Touchable) container to match its parent width
23+
button {
24+
width: inherit;
25+
}
1526
}
1627

1728
.componentExample {
@@ -34,4 +45,4 @@
3445
display: flex;
3546
justify-content: center;
3647
align-items: center;
37-
}
48+
}

docuilib/src/components/pageComponents/ContentItem.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import CodeIcon from '../../assets/icons/code';
1010
type ComponentItemProps = {
1111
componentName: string;
1212
props?: Record<string, unknown> | Record<string, unknown>[];
13-
snippet?: string
13+
snippet?: string;
14+
flexed?: boolean;
1415
showCodeButton?: boolean;
1516
};
1617

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

3536
const ComponentItem = (props: ComponentItemProps) => {
36-
const {componentName, props: componentProps, snippet, showCodeButton = false} = props;
37+
const {componentName, props: componentProps, snippet, flexed, showCodeButton = false} = props;
3738
const [showCode, setShowCode] = useState(false);
3839

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

5657
const componentPreview = (
57-
<div className={styles.blocker}>
58+
<div className={`${styles.blocker} ${flexed ? styles.flexed : ''}`}>
5859
<LiveProvider code={code} scope={ReactLiveScope}>
59-
<LivePreview/>
60+
<LivePreview style={{width: '100%'}}/>
6061
</LiveProvider>
6162
</div>
6263
);
@@ -84,22 +85,16 @@ type Item = {
8485
value?: any;
8586
snippet?: string;
8687
height?: number;
88+
flexed?: boolean;
8789
};
8890
type ContentItemProps = {
8991
item: Item;
9092
componentName: string;
9193
showCodeButton?: boolean;
94+
category: string;
9295
};
9396

94-
const extractComponentFromSnippet = (snippet: string) => {
95-
if (!snippet.startsWith('<')) {
96-
return;
97-
}
98-
const firstWord = snippet.split(' ')[0];
99-
return firstWord.slice(1);
100-
};
101-
102-
export const ContentItem = ({item, componentName, showCodeButton}: ContentItemProps) => {
97+
export const ContentItem = ({item, componentName, showCodeButton, category}: ContentItemProps) => {
10398
const getFigmaEmbed = (value: string, height = 450) => {
10499
const modifiedValue = !value.includes('page-selector=') ? value + '&page-selector=false' : value;
105100
return <iframe width={'100%'} height={height} src={modifiedValue}/>;
@@ -116,12 +111,22 @@ export const ContentItem = ({item, componentName, showCodeButton}: ContentItemPr
116111
const value = item.value;
117112

118113
if (item.props || item.snippet) {
119-
const name = item.snippet ? extractComponentFromSnippet(item.snippet) : item.component ?? componentName;
120-
const isComponentExists = !!(_.get(ReactLiveScope, name));
114+
let name = item.component ?? componentName;
115+
if (category === 'incubator') {
116+
name = `Incubator.${name}`;
117+
}
118+
119+
const isComponentExists = !!_.get(ReactLiveScope, name);
121120

122121
if (isComponentExists) {
123122
return (
124-
<ComponentItem componentName={name} props={item.props} snippet={item.snippet} showCodeButton={showCodeButton}/>
123+
<ComponentItem
124+
componentName={name}
125+
props={item.props}
126+
snippet={item.snippet}
127+
showCodeButton={showCodeButton}
128+
flexed={item.flexed}
129+
/>
125130
);
126131
} else if (!value) {
127132
return <div style={{color: 'red'}}>Component Not Supported</div>;

docuilib/src/components/pageComponents/SectionContent.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ export const SectionContent = ({section, component}) => {
1313
{_.map(content, (item, index: number) => {
1414
const isLast = index === content.length - 1;
1515

16-
return <div style={{marginBottom: isLast ? 0 : 40, border: '1px solid #F8F9FA', background: item.background}}><ContentItem item={item} componentName={component.name}/></div>;
16+
return (
17+
<div style={{marginBottom: isLast ? 0 : 40, border: '1px solid #F8F9FA', background: item.background}}>
18+
<ContentItem
19+
item={item}
20+
componentName={component.name}
21+
category={component.category}
22+
/>
23+
</div>
24+
);
1725
})}
1826
</div>
1927
);

docuilib/src/components/pageComponents/TableSection.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ export const TableSection = ({section, component}) => {
2222
if (index < numberOfColumns - 1) {
2323
return (
2424
<td style={{backgroundColor: item.background || 'white', padding: 0, height: '100px'}}>
25-
<ContentItem item={item} componentName={component.name} showCodeButton/>
25+
<ContentItem
26+
item={item}
27+
componentName={component.name}
28+
showCodeButton
29+
category={component.category}
30+
/>
2631
</td>
2732
);
2833
}

docuilib/src/theme/ReactLiveScope/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ Assets.loadAssetsGroup('icons.demo', {
3737
width: 24,
3838
height: 24
3939
},
40+
chevronDown: {
41+
uri: require('../../assets/icons/chevronDown.png').default,
42+
width: 14,
43+
height: 8
44+
},
45+
star: {
46+
uri: require('../../assets/icons/star.png').default,
47+
width: 24,
48+
height: 24
49+
},
4050
// add: require('../../assets/icons/add.png').default,
4151
// camera: require('../../assets/icons/cameraSelected.png').default,
4252
// close: require('../../assets/icons/close.png').default,

0 commit comments

Comments
 (0)