Skip to content

Commit a82faac

Browse files
evanyan13Evan Yan
andauthored
[CI-4303] Update Code Examples - Groups (#152)
* Update code examples for Groups * Add instruction --------- Co-authored-by: Evan Yan <evan.yan@constructor.io>
1 parent c833d0b commit a82faac

File tree

1 file changed

+48
-26
lines changed

1 file changed

+48
-26
lines changed

src/stories/components/Groups/Code Examples.mdx

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,26 @@ A separate filter component that allows you to filter down by groups.
2020

2121
## Basic example
2222

23+
To view the examples and see this component in action
24+
25+
- **Search** - append your URL with `?q=shirt`
26+
2327
```jsx
24-
import React from 'react';
25-
import { CioPlp, Groups } from '@constructor-io/constructorio-ui-plp';
28+
import { CioPlp, CioPlpGrid, Groups, utils } from '@constructor-io/constructorio-ui-plp';
29+
import '@constructor-io/constructorio-ui-plp/styles.css';
2630

27-
const apiKey = 'MY_API_KEY';
31+
const DEMO_API_KEY = 'key_M57QS8SMPdLdLx4x';
2832

29-
function MyComponent() {
33+
export default function MyComponent() {
3034
return (
31-
<CioPlp apiKey={MY_API_KEY}>
32-
<Groups />
35+
<CioPlp apiKey={DEMO_API_KEY}>
36+
<CioPlpGrid>
37+
{(props) => {
38+
if (utils.isPlpSearchDataResults(props.data)) {
39+
return <Groups groups={props.data.response.groups} />;
40+
}
41+
}}
42+
</CioPlpGrid>
3343
</CioPlp>
3444
);
3545
}
@@ -40,30 +50,42 @@ function MyComponent() {
4050
To override the default rendering of the Groups component, you may pass a Render Props function to the component.
4151

4252
```jsx
43-
import { CioPlp, Filters } from '@constructor-io/constructorio-ui-plp'
44-
45-
const apiKey = 'MY_API_KEY';
46-
47-
function MyCustomGroupFilter(props) {
48-
const {groups, initialNumOptions} = props
49-
50-
return (
51-
<>
52-
{/* CUSTOM_MARKUP_HERE */}
53-
</>
54-
);
53+
import { CioPlp, CioPlpGrid, Groups, utils } from '@constructor-io/constructorio-ui-plp';
54+
import '@constructor-io/constructorio-ui-plp/styles.css';
55+
56+
const DEMO_API_KEY = 'key_M57QS8SMPdLdLx4x';
57+
58+
function MyCustomGroups(props) {
59+
const {
60+
groupOptions,
61+
currentGroupId,
62+
breadcrumbs,
63+
currentPage,
64+
initialNumOptions,
65+
isShowAll,
66+
optionsToRender,
67+
} = props;
68+
return <pre>{JSON.stringify(groupOptions, null, 2)}</pre>;
5569
}
5670

57-
function myApp() {
58-
...
59-
71+
export default function MyComponent() {
6072
return (
61-
<CioPlp apiKey={MY_API_KEY}>
62-
<Groups>
63-
<MyCustomGroupFilter />
64-
</Groups>
73+
<CioPlp apiKey={DEMO_API_KEY}>
74+
<CioPlpGrid>
75+
{(props) => {
76+
if (utils.isPlpSearchDataResults(props.data)) {
77+
return (
78+
<Groups groups={props.data.response.groups}>
79+
{(groupProps) => {
80+
return <MyCustomGroups {...groupProps} />;
81+
}}
82+
</Groups>
83+
);
84+
}
85+
}}
86+
</CioPlpGrid>
6587
</CioPlp>
66-
)
88+
);
6789
}
6890
```
6991

0 commit comments

Comments
 (0)