2020-10-16 13:16:01 +00:00
|
|
|
import React from "react";
|
2021-03-02 14:20:16 +00:00
|
|
|
|
2021-03-07 11:57:26 +00:00
|
|
|
import CheckboxComponent from "./";
|
2021-03-02 14:20:16 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
title: "Components/Checkbox",
|
2021-03-07 11:57:26 +00:00
|
|
|
component: CheckboxComponent,
|
2021-03-02 14:20:16 +00:00
|
|
|
parameters: {
|
|
|
|
docs: {
|
|
|
|
description: { component: "Custom checkbox input" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
argTypes: {
|
|
|
|
onChange: {
|
|
|
|
action: "onChange",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-03-07 11:57:26 +00:00
|
|
|
class Checkbox extends React.Component {
|
2021-03-02 14:20:16 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
isChecked: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onChange = (e) => {
|
|
|
|
this.props.onChange(e);
|
|
|
|
this.setState({ isChecked: !this.state.isChecked });
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2021-03-07 11:57:26 +00:00
|
|
|
<CheckboxComponent
|
2021-03-02 14:20:16 +00:00
|
|
|
{...this.props}
|
|
|
|
isChecked={this.props.isChecked || this.state.isChecked}
|
|
|
|
onChange={this.onChange}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const Template = (args) => {
|
2021-03-07 11:57:26 +00:00
|
|
|
return <Checkbox {...args} />;
|
2021-03-02 14:20:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const AllCheckboxesTemplate = (args) => {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: "grid",
|
|
|
|
gridTemplateColumns: "repeat( auto-fill, minmax(120px, 1fr) )",
|
|
|
|
gridGap: "16px",
|
|
|
|
alignItems: "center",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Checkbox />
|
|
|
|
<Checkbox isChecked={true} />
|
|
|
|
<Checkbox isDisabled={true} />
|
|
|
|
<Checkbox isIndeterminate={true} />
|
|
|
|
<Checkbox label="Some label" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Default = Template.bind({});
|
2021-03-03 07:56:54 +00:00
|
|
|
Default.args = {
|
|
|
|
label: "Checkbox label",
|
|
|
|
};
|
2021-03-02 14:20:16 +00:00
|
|
|
export const AllCheckboxStates = AllCheckboxesTemplate.bind({});
|