Skip to content

Commit 26c9bd7

Browse files
joebuonoJoe Buono
andauthored
docs(update): Usage page (#2009)
* basic usage example * examples for theming and components * adjusting description * change links to relative paths Co-authored-by: Joe Buono <[email protected]>
1 parent c58c1e0 commit 26c9bd7

File tree

8 files changed

+184
-8
lines changed

8 files changed

+184
-8
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as React from 'react';
2+
import { Button } from '@aws-amplify/ui-react';
3+
import '@aws-amplify/ui-react/styles.css';
4+
5+
function App() {
6+
return (
7+
<Button
8+
ariaLabel="Add item to cart"
9+
backgroundColor="#ffd811"
10+
borderRadius="1rem"
11+
color="black"
12+
fontWeight="normal"
13+
onClick={() => alert('Added to cart! ✅')}
14+
size="small"
15+
width="8rem"
16+
>
17+
Add to Cart
18+
</Button>
19+
);
20+
}
21+
22+
export default App;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Button } from '@aws-amplify/ui-react';
2+
3+
export const ComponentExampleDemo = () => {
4+
return (
5+
<Button
6+
ariaLabel="Add item to cart"
7+
backgroundColor="#ffd811"
8+
borderRadius="1rem"
9+
color="black"
10+
fontWeight="normal"
11+
onClick={() => alert('Added to cart! ✅')}
12+
size="small"
13+
width="8rem"
14+
>
15+
Add to Cart
16+
</Button>
17+
);
18+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as React from 'react';
2+
import { Button } from '@aws-amplify/ui-react';
3+
import '@aws-amplify/ui-react/styles.css';
4+
5+
function App() {
6+
return <Button variation="primary">Hello world</Button>;
7+
}
8+
9+
export default App;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Button } from '@aws-amplify/ui-react';
2+
3+
export const ReactExampleDemo = () => {
4+
return <Button variation="primary">Hello world</Button>;
5+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Button, ThemeProvider } from '@aws-amplify/ui-react';
2+
import '@aws-amplify/ui-react/styles.css'; // default theme
3+
4+
const theme = {
5+
name: 'custom-button-theme',
6+
tokens: {
7+
components: {
8+
button: {
9+
// this will affect the font weight of all Buttons
10+
fontWeight: { value: '{fontWeights.black.value}' },
11+
// this will only style Buttons which are the "primary" variation
12+
primary: {
13+
backgroundColor: { value: 'rebeccapurple' },
14+
_hover: {
15+
backgroundColor: { value: 'hotpink' },
16+
},
17+
},
18+
},
19+
},
20+
},
21+
};
22+
23+
function App() {
24+
return (
25+
<ThemeProvider theme={theme}>
26+
<Button variation="primary">Custom button</Button>
27+
</ThemeProvider>
28+
);
29+
}
30+
31+
export default App;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Button, ThemeProvider } from '@aws-amplify/ui-react';
2+
3+
const theme = {
4+
name: 'custom-button-theme',
5+
tokens: {
6+
components: {
7+
button: {
8+
fontWeight: { value: '{fontWeights.black.value}' },
9+
primary: {
10+
backgroundColor: { value: 'rebeccapurple' },
11+
_hover: {
12+
backgroundColor: { value: 'hotpink' },
13+
},
14+
},
15+
},
16+
},
17+
},
18+
};
19+
export const ThemeExampleDemo = () => {
20+
return (
21+
<ThemeProvider theme={theme}>
22+
<Button variation="primary">Custom button</Button>
23+
</ThemeProvider>
24+
);
25+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { ComponentExampleDemo } from './ComponentExampleDemo';
2+
export { ReactExampleDemo } from './ReactExampleDemo';
3+
export { ThemeExampleDemo } from './ThemeExampleDemo';
Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,78 @@
11
import { Tabs, TabItem } from '@aws-amplify/ui-react';
22
import { Example, ExampleCode } from '@/components/Example';
3+
import {
4+
ComponentExampleDemo,
5+
ReactExampleDemo,
6+
ThemeExampleDemo,
7+
} from './examples';
38

4-
## Import styles and components
9+
## React and Amplify UI
510

6-
Load the default styling by importing our CSS:
11+
Amplify UI is designed to integrate seamlessly with the React framework so you can get started in no time.
712

8-
```jsx
9-
import { View } from '@aws-amplify/ui-react';
10-
import '@aws-amplify/ui-react/styles.css'; // default theme
13+
### Installation
14+
15+
If you haven't already, install `@aws-amplify/ui-react` with [npm](https://www.npmjs.com/) or [yarn](https://yarnpkg.com/):
16+
17+
<Tabs>
18+
<TabItem title="npm">
19+
20+
```shell
21+
npm install aws-amplify @aws-amplify/ui-react
22+
```
23+
24+
</TabItem>
25+
<TabItem title="yarn">
26+
27+
```shell
28+
yarn add aws-amplify @aws-amplify/ui-react
29+
```
30+
31+
</TabItem>
32+
</Tabs>
33+
34+
### Quick start
35+
36+
Here's all you need to get up and running:
37+
38+
<ExampleCode>
39+
```tsx file=./examples/ReactExampleCode.tsx
40+
41+
```
42+
</ExampleCode>
43+
44+
Copy/paste the code above into your React app, start the app, and look at that lovely Button!
45+
46+
<ReactExampleDemo />
47+
48+
### Components
49+
50+
You can use all of Amplify UI's primitive components (e.g., `Button`, `Tabs`, `Flex`) right out-of-the-box. These are the same components we use to build our connected components such as the [Authenticator](/react/components/authenticator). Please refer to each component's [documentation](/react/components/button) to see how they should be imported, configured and styled.
51+
52+
<Example>
53+
<ComponentExampleDemo />
54+
<ExampleCode>
55+
```tsx file=./examples/ComponentExampleCode.tsx
56+
57+
```
58+
</ExampleCode>
59+
</Example>
60+
61+
### Theming
62+
63+
Amplify UI ships with a default [theme](/react/theming) that you can customize to match the look and feel of your project. Remember to load the default styling by importing our CSS at the entry-point to your application (e.g., `src/App.js`).
64+
65+
```js
66+
import '@aws-amplify/ui-react/styles.css';
67+
```
68+
69+
To learn how to customize the appearance of all components in your application with a theme, see [theming](/react/theming).
70+
71+
<Example>
72+
<ThemeExampleDemo />
73+
<ExampleCode>
74+
```tsx file=./examples/ThemeExampleCode.tsx
1175

12-
export default function App() {
13-
return <View>Your app here</View>;
14-
}
1576
```
77+
</ExampleCode>
78+
</Example>

0 commit comments

Comments
 (0)