Skip to content

Commit a96466d

Browse files
Celeste GlavinAdam Raider
authored andcommitted
feat(radio): add radios (#27)
* add checkbox primary * add hover states * use class name * Add transition: * disabled state * add class for no outline * add mixin for no-select * add radios * add focus states * remoev focus, too weird * remove no-outline * fix color conflicts * unify * clean up class names * split up stories
1 parent 8ff572b commit a96466d

File tree

6 files changed

+132
-1
lines changed

6 files changed

+132
-1
lines changed

packages/ray/lib/application.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
@import './components/card/card';
1212
@import './components/button/button';
13+
@import './components/radio-checkbox/radio-checkbox';
1314
@import 'responsive';
1415
@import 'forms';
1516
@import 'image';
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
$radio-checkbox-border-width: 3px;
2+
$radio-checkbox-width: 1rem;
3+
4+
.#{$prefix}radio,
5+
.#{$prefix}checkbox {
6+
@include no-select;
7+
8+
label {
9+
padding-left: 1rem;
10+
}
11+
12+
&__input {
13+
appearance: none;
14+
background-color: $ray-color-white;
15+
border: $radio-checkbox-border-width double $ray-color-black;
16+
width: $radio-checkbox-width;
17+
height: $radio-checkbox-width;
18+
transform: translateY(16%);
19+
20+
&::after {
21+
content: '';
22+
width: calc(#{$radio-checkbox-width} - 2 * #{$radio-checkbox-border-width});
23+
height: calc(#{$radio-checkbox-width} - 2 * #{$radio-checkbox-border-width});
24+
background: $ray-color-white;
25+
display: block;
26+
transition: $transition;
27+
}
28+
29+
&:checked {
30+
border-color: $ray-color-blue-50;
31+
32+
&::after {
33+
background: $ray-color-blue-50;
34+
}
35+
36+
&:hover {
37+
border-color: $ray-color-blue-70;
38+
39+
&::after {
40+
background: $ray-color-blue-70;
41+
}
42+
}
43+
}
44+
45+
&:not(:checked) {
46+
&:hover {
47+
&::after {
48+
background: $ray-color-blue-10;
49+
}
50+
}
51+
}
52+
53+
&[disabled] {
54+
border-color: #B0B0B0;
55+
56+
&:hover {
57+
&::after {
58+
background: $ray-color-white;
59+
}
60+
}
61+
62+
+ label {
63+
cursor: not-allowed;
64+
color: #B0B0B0;
65+
}
66+
}
67+
}
68+
}
69+
70+
.#{$prefix}radio__input {
71+
border-radius: 50%;
72+
73+
&::after {
74+
border-radius: 50%;
75+
}
76+
}
77+
78+
.#{$prefix}checkbox__input {
79+
border-radius: $border-radius;
80+
}

packages/ray/lib/global/_functions.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@
2929
@warn "First breakpoint in `$grid-breakpoints` must start at 0, but starts at #{$first-value}.";
3030
}
3131
}
32+
33+
@mixin no-select {
34+
-webkit-touch-callout: none; /* iOS Safari */
35+
-webkit-user-select: none; /* Safari */
36+
-khtml-user-select: none; /* Konqueror HTML */
37+
-moz-user-select: none; /* Firefox */
38+
-ms-user-select: none; /* Internet Explorer/Edge */
39+
user-select: none; /* Non-prefixed version, currently supported by Chrome and Opera */
40+
}

packages/ray/lib/global/_variables.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ $font-stack-sans-serif: 'Apercu', Avenir, -apple-system, BlinkMacSystemFont,
44
'Helvetica Neue', Helvetica, 'Calibri', 'Roboto', Arial, sans-serif !default;
55
$font-stack-mono: 'Apercu Mono', monospace !default;
66

7+
$transition: all 0.125s ease;
8+
79
$breakpoint-mobile-px: 400px !default;
810
$breakpoint-tablet-px: 600px !default;
911
$breakpoint-desktop-px: 840px !default;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
import { storiesOf } from '@storybook/react';
3+
4+
import withPadding from './util/withPadding';
5+
6+
storiesOf('Forms - Radio buttons and Checkboxes', module)
7+
.addWithJSX('Radio button', () =>
8+
withPadding(
9+
<React.Fragment>
10+
<div className="ray-radio">
11+
<input id="radio-1" name="radio-button-story" type="radio" className="ray-radio__input" />
12+
<label htmlFor="radio-1">Choose me</label>
13+
</div>
14+
<div className="ray-radio">
15+
<input id="radio-2" name="radio-button-story" type="radio" className="ray-radio__input" />
16+
<label htmlFor="radio-2">Choose me</label>
17+
</div>
18+
<div className="ray-radio">
19+
<input id="radio-3" name="radio-button-story" type="radio" className="ray-radio__input" disabled />
20+
<label htmlFor="radio-3">Choose me</label>
21+
</div>
22+
</React.Fragment>
23+
))
24+
.addWithJSX('Checkbox', () =>
25+
withPadding(
26+
<div className="ray-checkbox">
27+
<input id="check" type="checkbox" className="ray-checkbox__input" />
28+
<label htmlFor="check">Check me out</label>
29+
</div>
30+
)
31+
)
32+
.addWithJSX('Checkbox - disabled', () =>
33+
withPadding(
34+
<div className="ray-checkbox">
35+
<input id="check" type="checkbox" className="ray-checkbox__input" disabled />
36+
<label htmlFor="check">Check me out</label>
37+
</div>
38+
)
39+
);

packages/ray/stories/forms.stories.js renamed to packages/ray/stories/textFields.stories.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { storiesOf } from '@storybook/react';
33

44
import withPadding from './util/withPadding';
55

6-
storiesOf('Forms', module)
6+
storiesOf('Forms - Text Fields', module)
77
.addWithJSX('Text field', () =>
88
withPadding(
99
<div className="ray-field">

0 commit comments

Comments
 (0)