-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
1 parent
07f7537
commit 889ebd5
Showing
20 changed files
with
715 additions
and
283 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
72 changes: 72 additions & 0 deletions
72
packages/@ourworldindata/grapher/src/controls/RadioButton.scss
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,72 @@ | ||
.radio { | ||
$radio-size: 16px; | ||
|
||
$light-stroke: #dadada; | ||
$hover-stroke: #a4b6ca; | ||
$active-fill: #dbe5f0; | ||
|
||
position: relative; | ||
|
||
input { | ||
position: absolute; | ||
opacity: 0; | ||
left: 0; | ||
cursor: pointer; | ||
} | ||
|
||
.outer { | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
content: " "; | ||
width: $radio-size; | ||
height: $radio-size; | ||
|
||
background: white; | ||
pointer-events: none; | ||
border-radius: 50%; | ||
border: 1px solid #a4b6ca; | ||
color: $dark-text; | ||
|
||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
.inner { | ||
display: none; | ||
width: $radio-size / 2; | ||
height: $radio-size / 2; | ||
background-color: #6e87a2; | ||
border-radius: 50%; | ||
} | ||
} | ||
|
||
input:focus-visible + .outer { | ||
outline: 2px solid $controls-color; | ||
} | ||
|
||
input:active + .outer > .inner { | ||
display: block; | ||
} | ||
|
||
input:checked + .outer > .inner { | ||
display: block; | ||
} | ||
|
||
input:checked:active + .outer > .inner { | ||
display: block; | ||
} | ||
|
||
.label { | ||
@include grapher_label-2-regular; | ||
padding-left: $radio-size + 8px; | ||
cursor: pointer; | ||
user-select: none; | ||
} | ||
|
||
&:hover { | ||
input:not(:checked) + .custom { | ||
border-color: $hover-stroke; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/@ourworldindata/grapher/src/controls/RadioButton.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,31 @@ | ||
import React from "react" | ||
|
||
export class RadioButton extends React.Component<{ | ||
checked: boolean | ||
onChange: React.ChangeEventHandler<HTMLInputElement> | ||
label: React.ReactNode | ||
group?: string | ||
}> { | ||
render(): JSX.Element { | ||
const { checked, onChange, label, group } = this.props | ||
|
||
return ( | ||
<div className="radio"> | ||
<label> | ||
<input | ||
type="radio" | ||
name={group} | ||
checked={checked} | ||
onChange={onChange} | ||
/> | ||
<div className="outer"> | ||
{checked && <div className="inner" />} | ||
</div> | ||
<div className="label"> | ||
{label} {checked} | ||
</div> | ||
</label> | ||
</div> | ||
) | ||
} | ||
} |
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
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
Oops, something went wrong.