Skip to content
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

Docs: Add live docs to SegementedControl #90

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

* Docs: Add live docs to Toast (#87)
* Internal: Convert `BrowserRouter` to `HashRouter` - fixes directly going to a component (#88)
* Docs: Add live docs to SegmentedControl (#90)

## 0.60.0 (March 13, 2018)

Expand Down
107 changes: 37 additions & 70 deletions docs/src/SegmentedControl.doc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @flow
import * as React from 'react';
import { Box, SegmentedControl } from 'gestalt';
import PropTable from './components/PropTable';
import StateRecorder from './components/StateRecorder';
import Example from './components/Example';
import PageHeader from './components/PageHeader';
import CardPage from './components/CardPage';

Expand Down Expand Up @@ -41,84 +40,52 @@ card(
required: true,
description: 'Index of element in `items` that is selected.',
},
{
name: 'size',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nithindavid Thank you for catching this!

type: '"md" | "lg"',
required: false,
description: 'Size of the Segemented control.',
defaultValue: 'md',
},
]}
heading={false}
/>
);

card(
<Box
description={`
There are 2 different sizes for segmented controls. The default size is \`md\`.

~~~html
<SegmentedControl
selectedItemIndex={0}
items={['Athos', 'Porthos', 'Aramis']}
/>
~~~

~~~html
<SegmentedControl
selectedItemIndex={0}
size="lg"
items={['Athos', 'Porthos', 'Aramis']}
/>
~~~
`}
name="Sizes"
>
<Box padding={2}>
<SegmentedControl
onChange={() => {}}
selectedItemIndex={0}
items={['Athos', 'Porthos', 'Aramis']}
/>
</Box>
<Box padding={2}>
<SegmentedControl
onChange={() => {}}
selectedItemIndex={0}
size="lg"
items={['Athos', 'Porthos', 'Aramis']}
/>
</Box>
</Box>
);

card(
<StateRecorder
description={`
Segmented Controls are naive components, meaning you need to write up the behavior when you click on an item.
<Example
description="Segmented Controls are naive components, meaning you need to write up the behavior when you click on an item.

If you'd like the tabs to control hiding or showing content that state should
live in a parent component.

~~~js
<SegmentedControl
selectedItemIndex={0}
items={['News', 'You', 'Messages']}
onChange={() => {}}
/>
~~~
`}
"
name="Example"
fn={atom => {
const state = atom.deref();
return (
<SegmentedControl
items={['News', 'You', 'Messages']}
selectedItemIndex={0}
{...state}
onChange={({ activeIndex }) =>
atom.set(props => ({
...props,
selectedItemIndex: activeIndex,
}))
}
/>
);
}}
defaultCode={`
class ToastExample extends React.Component {
constructor(props) {
super(props);
this.state = {
itemIndex: 0,
items: ['News', 'You', 'Messages']
};
this.handleItemChange = this.handleItemChange.bind(this);
}

handleItemChange({ activeIndex }) {
this.setState(prevState => ({ itemIndex: activeIndex }));
};

render() {
return (
<SegmentedControl
items={this.state.items}
selectedItemIndex={this.state.itemIndex}
onChange={this.handleItemChange}
/>
);
}
}
`}
/>
);

Expand Down