-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
106 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import * as React from "react"; | ||
import styled from "@emotion/styled"; | ||
import type { RadioProps as MuiRadioProps } from "@material-ui/core"; | ||
import { Radio as MuiRadio } from "@material-ui/core"; | ||
|
||
const StyledRadio = styled(MuiRadio)( | ||
{ | ||
".MuiIconButton-label": { | ||
height: "24px", | ||
width: "24px", | ||
borderRadius: "100px", | ||
boxSizing: "border-box", | ||
}, | ||
}, | ||
props => ({ | ||
"&:hover > .MuiIconButton-label > div": { | ||
border: props.checked ? "1px solid #283CD2" : "1px solid #2E45DC", | ||
}, | ||
}) | ||
); | ||
|
||
const Icon = styled.div( | ||
{ | ||
height: "24px", | ||
width: "24px", | ||
border: "1px solid rgba(13, 16, 48, 0.38)", | ||
borderRadius: "100px", | ||
boxSizing: "border-box", | ||
}, | ||
props => ({ | ||
border: props["data-disabled"] ? "1px solid #DFE2E4" : "1px solid rgba(13, 16, 48, 0.38)", | ||
}) | ||
); | ||
|
||
const SelectedIcon = styled.div({ | ||
height: "24px", | ||
width: "24px", | ||
background: "#2E45DC", | ||
border: "1px solid #283CD2", | ||
borderRadius: "100px", | ||
boxSizing: "border-box", | ||
}); | ||
|
||
const SelectedCenter = styled.div({ | ||
height: "12px", | ||
width: "12px", | ||
background: "#FFFFFF", | ||
borderRadius: "100px", | ||
boxSizing: "border-box", | ||
margin: "5px 5px", | ||
}); | ||
|
||
export interface RadioProps extends Pick<MuiRadioProps, "disabled" | "value"> { | ||
selected?: boolean; | ||
} | ||
|
||
const Radio: React.FC<RadioProps> = ({ selected, disabled, value }) => { | ||
return ( | ||
<StyledRadio | ||
checked={selected} | ||
icon={<Icon data-disabled={disabled} />} | ||
checkedIcon={ | ||
<SelectedIcon> | ||
<SelectedCenter /> | ||
</SelectedIcon> | ||
} | ||
color="primary" | ||
value={value} | ||
disabled={disabled} | ||
/> | ||
); | ||
}; | ||
|
||
export default Radio; |
27 changes: 27 additions & 0 deletions
27
frontend/packages/core/src/Input/stories/radio.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from "react"; | ||
import type { Meta } from "@storybook/react"; | ||
|
||
import type { RadioProps } from "../radio"; | ||
import Radio from "../radio"; | ||
|
||
export default { | ||
title: "Core/Input/Radio", | ||
component: Radio, | ||
} as Meta; | ||
|
||
const Template = (props: RadioProps) => <Radio {...props} />; | ||
|
||
export const Primary = Template.bind({}); | ||
Primary.args = { | ||
selected: false, | ||
}; | ||
|
||
export const Selected = Template.bind({}); | ||
Selected.args = { | ||
selected: true, | ||
}; | ||
|
||
export const Disabled = Template.bind({}); | ||
Disabled.args = { | ||
disabled: true, | ||
}; |