Skip to content

Commit 55981c8

Browse files
committed
fix: make table responsive in ui builder section
1 parent 23c4cbf commit 55981c8

File tree

2 files changed

+95
-86
lines changed

2 files changed

+95
-86
lines changed

mdx-components.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import { ExternalLinkButton } from './src/components/ExternalLinkButton';
1717
import InternalLink from './src/components/InternalLink';
1818
import { InternalLinkButton } from './src/components/InternalLinkButton';
1919
import FilterContent from './src/components/FilterContent';
20-
import { Grid } from '@aws-amplify/ui-react';
20+
import { Grid, View } from '@aws-amplify/ui-react';
21+
import { Columns } from './src/components/Columns';
2122

2223
const ResponsiveImage = (props) => (
2324
<ExportedImage style={{ height: 'auto' }} {...props} />
@@ -66,6 +67,8 @@ export function useMDXComponents(components: MDXComponents): MDXComponents {
6667
InternalLinkButton,
6768
FilterContent,
6869
Grid,
70+
Columns,
71+
View,
6972
...components
7073
};
7174
}

src/pages/[platform]/build-ui/uibuilder/override/index.mdx

Lines changed: 91 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';
2-
2+
33
export const meta = {
44
title: 'Extend with code',
55
description: 'Figma to React code with Amplify Studio',
66
platforms: [
7-
'android',
8-
'angular',
9-
'flutter',
10-
'javascript',
11-
'nextjs',
12-
'react',
13-
'react-native',
14-
'swift',
15-
'vue'
16-
]
7+
'android',
8+
'angular',
9+
'flutter',
10+
'javascript',
11+
'nextjs',
12+
'react',
13+
'react-native',
14+
'swift',
15+
'vue'
16+
]
1717
};
1818

1919
export const getStaticPaths = async () => {
@@ -28,13 +28,13 @@ export function getStaticProps(context) {
2828
}
2929
};
3030
}
31-
3231

33-
When you run `amplify pull`, Amplify automatically generates JSX and TS versions of your Figma components. You cannot directly edit the code for these components as they will get overwritten on the next `pull`, but you have exposed mechanisms to extend the code.
32+
When you run `amplify pull`, Amplify automatically generates JSX and TS versions of your Figma components. You cannot directly edit the code for these components as they will get overwritten on the next `pull`, but you have exposed mechanisms to extend the code.
3433

3534
## Extend generated code
3635

3736
### Extend generated code via component prop
37+
3838
When using Figma created components, you can use any exposed component props. The example code below shows how you can add pagination to a collection. The `isPaginated` prop is a property of the [`<Collection/>`](https://ui.docs.amplify.aws/react/components/collection) component. Similarly, you can use any prop such as `gap` or `isSearchable` to extend the collection.
3939

4040
```
@@ -45,43 +45,45 @@ import {AmpligramCollection} from './ui-components'
4545
```
4646

4747
### Extend generated components via overrides prop
48+
4849
All generated code exposes an `overrides` prop on all components and children to give you full control over extending generated code. The following example shows how to override the color of the title of the `FAQItem` component, that is part of the default Figma file, to red.
4950

50-
1. In Studio, navigate to the `FAQItem` component
51-
2. Find the name of the text element, in this case `Title`
52-
3. Wherever you are rendering the `FAQItem` add an `overrides` prop.
51+
1. In Studio, navigate to the `FAQItem` component
52+
2. Find the name of the text element, in this case `Title`
53+
3. Wherever you are rendering the `FAQItem` add an `overrides` prop.
5354

54-
<table>
55-
<tbody>
56-
<tr>
57-
<td>
55+
<Grid templateColumns={{ base: '1fr', large: '240px 1fr' }} gap="small">
56+
<View maxWidth="240px" margin="auto">
57+
![Overriding the color of a text element called
58+
Title](/images/console/ui-override.png)
59+
</View>
5860

59-
![Overriding the color of a text element called Title](/images/console/ui-override.png)
61+
<View minWidth="0">
6062

61-
</td>
62-
<td>
63+
```jsx import {FAQItem} from './ui-components'
64+
... ... //⬇️ Element name
65+
shown in Studio
66+
<FAQItem overrides={{ Title: { color: 'red' } }} />
67+
```
6368

64-
```jsx
65-
import {FAQItem} from './ui-components'
66-
...
67-
... //⬇️ Element name shown in Studio
68-
<FAQItem overrides={{"Title": { color: "red" } }}/>
69-
```
70-
</td>
71-
</tr>
72-
</tbody>
73-
</table>
69+
</View>
70+
71+
</Grid>
7472

7573
### Extend generated collections via overrideItems prop
74+
7675
All generated Collection code exposes an `overrideItems` prop to give you full control to extend each collection item with context its data item. `overrideItems` expects a function that accepts an `{ item, index }` parameter and returns the override props that should be applied to each collection item.
7776

7877
The following example shows how to override each collection item to show a different color based on their index in the collection and alerts the user of which the clicked home.
7978

8079
```jsx
81-
<HomeCollection overrideItems={({ item, index }) => ({
82-
backgroundColor: index % 2 === 0 ? 'white' : 'lightgray',
83-
onClick: () => alert(`Home with id: ${item.id} and ${item.address} clicked!`)
84-
})} />
80+
<HomeCollection
81+
overrideItems={({ item, index }) => ({
82+
backgroundColor: index % 2 === 0 ? 'white' : 'lightgray',
83+
onClick: () =>
84+
alert(`Home with id: ${item.id} and ${item.address} clicked!`)
85+
})}
86+
/>
8587
```
8688

8789
![Collection item shows a different color based on their index in the collection and alerts the user of which the clicked home](/images/console/collection-override.gif)
@@ -96,72 +98,71 @@ If you want to override a prop for a specific element within a collection item,
9698

9799
<Callout info>
98100

99-
**Note**: Studio supports nested collections with any GraphQL API created with Amplify, [with and without DataStore](/console/data/data-model/#datastore-and-graphql). However, these different data types have different syntax.
101+
**Note**: Studio supports nested collections with any GraphQL API created with Amplify, [with and without DataStore](/console/data/data-model/#datastore-and-graphql). However, these different data types have different syntax.
100102

101103
</Callout>
102104

103-
Component slots within collections allow you to conditionally render additional nested collections. For example, use nested collections to generate a collection of posts, each with its own collection of related comments.
105+
Component slots within collections allow you to conditionally render additional nested collections. For example, use nested collections to generate a collection of posts, each with its own collection of related comments.
104106

105-
In this example, you have two collections: `AmpligramCollection`, which has a slot named `comments`, and `CommentViewCollection`. These are bound to the `Post` and `Comment` data models, which have a [one-to-many relationship](/console/data/relationships/) - therefore, each record in the `Post` data model has a field named `Comments`, whose value is an array of `Comment` records.
107+
In this example, you have two collections: `AmpligramCollection`, which has a slot named `comments`, and `CommentViewCollection`. These are bound to the `Post` and `Comment` data models, which have a [one-to-many relationship](/console/data/relationships/) - therefore, each record in the `Post` data model has a field named `Comments`, whose value is an array of `Comment` records.
106108

107-
First, nest the `CommentViewCollection` within the `comment` component slot in the `AmpligramCollection` by using the `overrideItems` functionality. This will render every item in the `CommentViewCollection` in each `Ampligram` slot.
109+
First, nest the `CommentViewCollection` within the `comment` component slot in the `AmpligramCollection` by using the `overrideItems` functionality. This will render every item in the `CommentViewCollection` in each `Ampligram` slot.
108110

109111
```jsx
110-
import {
111-
AmpligramCollection,
112-
CommentViewCollection
113-
} from './ui-components'
112+
import { AmpligramCollection, CommentViewCollection } from './ui-components';
114113

115114
function App() {
116115
return (
117-
<AmpligramCollection overrideItems={({ item, index }) => ({
118-
comments: <CommentViewCollection /> //Add the child collection to the "comments" slot
119-
})} />
116+
<AmpligramCollection
117+
overrideItems={({ item, index }) => ({
118+
comments: <CommentViewCollection /> //Add the child collection to the "comments" slot
119+
})}
120+
/>
120121
);
121122
}
122123
export default App;
123124
```
124125

125-
Next, filter the `CommentViewCollection` to only include `Comment` records related to each `Ampligram`. To filter the `CommentViewCollection`, set the `items` prop equal to the array of `Comment` records. **This syntax varies based on whether you are using DataStore**.
126+
Next, filter the `CommentViewCollection` to only include `Comment` records related to each `Ampligram`. To filter the `CommentViewCollection`, set the `items` prop equal to the array of `Comment` records. **This syntax varies based on whether you are using DataStore**.
126127

127128
**DataStore**
128129

129130
```jsx
130-
import {
131-
AmpligramCollection,
132-
CommentViewCollection
133-
} from './ui-components'
131+
import { AmpligramCollection, CommentViewCollection } from './ui-components';
134132

135133
function App() {
136134
return (
137-
<AmpligramCollection overrideItems={({ item, index }) => ({
138-
/*Set the items in this collection to be only related items*/
139-
comments: <CommentViewCollection items={item.Comments} />
140-
})} />
135+
<AmpligramCollection
136+
overrideItems={({ item, index }) => ({
137+
/*Set the items in this collection to be only related items*/
138+
comments: <CommentViewCollection items={item.Comments} />
139+
})}
140+
/>
141141
);
142142
}
143143
export default App;
144144
```
145145

146146
**GraphQL without DataStore**
147+
147148
```jsx
148-
import {
149-
AmpligramCollection,
150-
CommentViewCollection
151-
} from './ui-components'
149+
import { AmpligramCollection, CommentViewCollection } from './ui-components';
152150

153151
function App() {
154152
return (
155-
<AmpligramCollection overrideItems={({ item, index }) => ({
156-
/*Set the items in this collection to be only related items*/
157-
comments: <CommentViewCollection items={item.Comments.items} />
158-
})} />
153+
<AmpligramCollection
154+
overrideItems={({ item, index }) => ({
155+
/*Set the items in this collection to be only related items*/
156+
comments: <CommentViewCollection items={item.Comments.items} />
157+
})}
158+
/>
159159
);
160160
}
161161
export default App;
162162
```
163163

164164
### Add business logic during or after action execution
165+
165166
If your components are bound to a [GraphQL API using DataStore](/console/data/data-model/#datastore-and-graphql), you can use the Amplify Hub to listen to actions that are executed via [UI event handlers](/console/uibuilder/eventhandling) and then add your custom business logic.
166167

167168
```jsx
@@ -177,8 +178,8 @@ Hub.listen("ui", (capsule) => {
177178

178179
In the example above, you can add your own custom business logic, when the customer clicks on a "Sign out" button. The Amplify `Hub` provides Studio-generated events on the `ui` channel. The format of action binding Hub events is `actions:[category]:[action_name]:[status]`:
179180

180-
| Action name | Description |
181-
|---|---|
181+
| Action name | Description |
182+
| --- | --- |
182183
| actions:core:navigate:started | [Navigate action](/console/uibuilder/eventhandling/#bind-ui-to-navigation-actions) started |
183184
| actions:core:navigate:finished | [Navigate action](/console/uibuilder/eventhandling/#bind-ui-to-navigation-actions) finished (possibly with errors) |
184185
| actions:datastore:create:started | [DataStore create action](/console/uibuilder/eventhandling/#create-a-record-in-database) started |
@@ -187,10 +188,11 @@ In the example above, you can add your own custom business logic, when the custo
187188
| actions:datastore:update:finished | [DataStore update action](/console/uibuilder/eventhandling/#update-a-record-from-database) finished (possibly with errors) |
188189
| actions:datastore:delete:started | [DataStore delete action](/console/uibuilder/eventhandling/#delete-a-record-from-database) started |
189190
| actions:datastore:delete:finished | [DataStore delete action](/console/uibuilder/eventhandling/#delete-a-record-from-database) finished (possibly with errors) |
190-
| actions:auth:signout:started | [SignOut action](/console/uibuilder/eventhandling/#bind-ui-to-sign-out-actions) started |
191+
| actions:auth:signout:started | [SignOut action](/console/uibuilder/eventhandling/#bind-ui-to-sign-out-actions) started |
191192
| actions:auth:signout:finished | [SignOut action](/console/uibuilder/eventhandling/#bind-ui-to-sign-out-actions) finished (possibly with errors) |
192193

193194
## Modify generated code
195+
194196
You can't directly customize all generated component code, as changes will be overwritten on the next `amplify pull`. However, the following workaround is available if you want to take control of component modifications.
195197

196198
1. Duplicate the generated JSX and TS file inside `ui-components` (e.g. `Ampligram`)
@@ -201,6 +203,7 @@ You can't directly customize all generated component code, as changes will be ov
201203
The next `amplify pull` will not overwrite this new file.
202204

203205
## Example use cases
206+
204207
The following code snippets show how you can handle specific scenarios in your app.
205208

206209
### Add Pagination to a collection
@@ -211,19 +214,21 @@ import {AmpligramCollection} from './ui-components'
211214
<AmpligramCollection isPaginated itemsPerPage={3}/>
212215
213216
```
217+
214218
### Make a component responsive
215-
Figma components that use *Auto layout* are automatically mapped to responsive React components. However, some components may require further customizations.
219+
220+
Figma components that use _Auto layout_ are automatically mapped to responsive React components. However, some components may require further customizations.
216221

217222
Use breakpoints to define behavior:
218223

219224
```jsx
220-
<NavBar width={{ small: "300px", large: "600px", xl: "800px" }}/>
225+
<NavBar width={{ small: '300px', large: '600px', xl: '800px' }} />
221226
```
222227

223-
or
228+
or
224229

225230
```jsx
226-
<NavBar width={"100vw"}/>
231+
<NavBar width={'100vw'} />
227232
```
228233

229234
### Set hover states on icons
@@ -261,7 +266,6 @@ const iconOverrides = {
261266
</tbody>
262267
</table>
263268

264-
265269
### Save form data
266270

267271
<Callout warning>
@@ -280,7 +284,7 @@ Get the override keys based on the element name in Studio and then set `onChange
280284
const [name, setName] = useState("");
281285
const [location, setLocation] = useState("");
282286
const [email, setEmail] = useState("");
283-
287+
284288
const profileOverrides = {
285289
"TextFieldzoh": {
286290
onChange: (event) => { setName(event.target.value) }
@@ -305,19 +309,21 @@ return (
305309

306310
### Navigation from parent to detail views
307311

308-
Amplify Studio provides [navigation action bindings](/console/uibuilder/eventhandling/#bind-ui-to-navigation-actions) but if you want to integrate with your own routing system, you can also self-manage the navigation actions.
312+
Amplify Studio provides [navigation action bindings](/console/uibuilder/eventhandling/#bind-ui-to-navigation-actions) but if you want to integrate with your own routing system, you can also self-manage the navigation actions.
309313

310314
For example, you want to click on an item in a collection to get to detail views. Use the `overrideItems` prop to modify each element's property within a collection. The return value of `overrideItems` will be applied as an override onto the collection item's component.
311315

312316
```jsx
313-
<HomeCollection overrideItems={({item, index}) => ({
314-
style: {
315-
cursor: "pointer"
316-
},
317-
onClick: () => {
318-
// The actual redirect can happen whichever way you want
319-
// `item` represent the data item that is passed into the
320-
// collection item. In this case, it's a "home".
321-
}
322-
})} />
317+
<HomeCollection
318+
overrideItems={({ item, index }) => ({
319+
style: {
320+
cursor: 'pointer'
321+
},
322+
onClick: () => {
323+
// The actual redirect can happen whichever way you want
324+
// `item` represent the data item that is passed into the
325+
// collection item. In this case, it's a "home".
326+
}
327+
})}
328+
/>
323329
```

0 commit comments

Comments
 (0)