Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 43525c2

Browse files
committedDec 24, 2018
Adds default button theme, and box-sizing of all elements
Fixes #16 Fixes #34
1 parent 742647b commit 43525c2

File tree

4 files changed

+97
-126
lines changed

4 files changed

+97
-126
lines changed
 

‎docs/button.md

Lines changed: 3 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ as a new entry into the history stack;
4242
the button. It is supposed to control button size, and although any values can
4343
be used, it is recommended to stick with `xs`, `sm`, `md`, `lg`, and `xl` size
4444
labels, with `md` size being the default, when no `size` property is passed in;
45-
- **`theme`** — *Object* — Button theme. This object is
45+
- **`theme`** — *Object* — Optional. Button theme. This object is
4646
supposed to have the following fields:
4747
- **`button`** — *String* — The class to apply to the root element
4848
of the button in all cases;
@@ -64,132 +64,11 @@ URL/location.
6464
effect only when Button is rendered as `<button>`.
6565

6666
### <a name="examples">Examples</a>
67-
First of all, you want to define button theme, here is a good example to start from:
68-
```scss
69-
// theme.scss
70-
71-
/* Base button style (medium size). */
72-
.button {
73-
align-items: center;
74-
background: while;
75-
border: solid 1px black;
76-
color: black;
77-
display: inline-flex;
78-
font: normal 15px arial;
79-
justify-content: center;
80-
min-height: 40px;
81-
margin: 5px;
82-
padding: 5px 23px;
83-
vertical-align: middle;
84-
}
85-
86-
/* Extra styling for the disabled buttons. */
87-
.disabled {
88-
cursor: not-allowed;
89-
opacity: 0.3;
90-
}
91-
92-
/* .link and .regular classes are applied only to active buttons and button-like
93-
* links. Here we provide visual feedback for button "active", "focus", and
94-
* "hover" states. */
95-
.link,
96-
.regular {
97-
/* To ensure that visited button-like links look the same as the non-visited
98-
* ones (as typical buttons should not look different if they used to be clicked
99-
* before). */
100-
&:visited {
101-
color: black;
102-
font: normal 15px arial;
103-
}
104-
105-
&:focus {
106-
box-shadow: 0 0 2px 1px #cfe6ff;
107-
border-color: #59a7ff;
108-
outline: none;
109-
}
110-
111-
&:hover {
112-
background-image: linear-gradient(to top, #f5f5f5, white 49%, white);
113-
border-color: $tc-gray-40;
114-
}
115-
116-
/* We need both ":active" selector and ".active" class here, if we want to
117-
* properly support the "active" option of the <Button>. */
118-
&.active,
119-
&:active {
120-
background-image: linear-gradient(to bottom, #f5f5f5, white 49%, white);
121-
box-shadow: inset 0 1px 2px 0 rgba(0, 0, 0, 0.2);
122-
border-color: $tc-gray-40;
123-
}
124-
}
125-
126-
/* And a few extra classes to support "xs", "sm", and "lg" button sizes. */
127-
.xs {
128-
font: normal 11px arial;
129-
min-height: 20px;
130-
padding: 1px 13px;
131-
}
132-
133-
.sm {
134-
font: normal 13px arial;
135-
min-height: 30px;
136-
padding: 4px 18px;
137-
}
138-
139-
.lg {
140-
font: normal 17px arial;
141-
min-height: 50px;
142-
padding: 5px 28px;
143-
}
144-
```
145-
146-
You can apply this theme directly to your `<Button>`, but it is more
147-
convenient to use
148-
[react-css-super-themr](https://www.npmjs.com/package/react-css-super-themr)
149-
for management of the button default / context / and ad-hoc theming. To use it,
150-
you should wrap the `<Button>` component with `themr(..)` decorator:
15167
```jsx
152-
// ThemedButton.js
153-
import { Button } from 'topcoder-react-utils';
154-
import { themr } from 'react-css-super-themr';
155-
import theme from './theme.scss';
156-
157-
export default const ThemedButton = themr('ThemedButton', theme)(Button);
158-
```
159-
160-
Now you can use the button in your code in multiple ways:
161-
```js
16268
import React from 'react';
163-
import { ThemeProvider } from 'react-css-super-themr';
164-
import Button from './ThemedButton';
165-
166-
// Some themes we want to use for the ad-hoc and context theming.
167-
import adHocTheme from './adHocStyle.scss';
168-
import contextTheme from './contextTheme';
69+
import { Button } from 'topcoder-react-utils';
16970

17071
export default function Example() {
171-
return (
172-
<div>
173-
<Button
174-
// Button with the default theme.
175-
onClick={() => console.log('Clicked!')}
176-
>Click Me!</Button>
177-
178-
<Button
179-
// Button-like link with ad-hoc theming.
180-
theme={adHocTheme}
181-
to="https://www.topcoder.com"
182-
>Click Me!</Button>
183-
184-
<ThemeProvider
185-
theme={{ ThemedButton: contextTheme }}
186-
>
187-
<Button
188-
// Button with context theming.
189-
onClick={() => console.log('Clicked!')}
190-
>Click Me!</Button>
191-
</ThemeProvider>
192-
</div>
193-
);
72+
return <Button to="https://topcoder.com">Simple Button</Button>;
19473
}
19574
```

‎src/shared/components/Button.jsx renamed to ‎src/shared/components/Button/index.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import PT from 'prop-types';
99
import React from 'react';
1010

11-
import Link from './Link';
11+
import Link from 'components/Link';
12+
13+
import defaultTheme from './style.scss';
1214

1315
export default function Button({
1416
active,
@@ -88,6 +90,7 @@ Button.defaultProps = {
8890
openNewTab: false,
8991
replace: false,
9092
size: null,
93+
theme: defaultTheme,
9194
to: null,
9295
type: 'button',
9396
};
@@ -107,7 +110,7 @@ Button.propTypes = {
107110
disabled: PT.string,
108111
link: PT.string,
109112
regular: PT.string,
110-
}).isRequired,
113+
}),
111114
to: PT.oneOfType([PT.object, PT.string]),
112115
type: PT.oneOf(['button', 'reset', 'submit']),
113116
};
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* The default button theme.
3+
*
4+
* The comments in this file explain how to write a custom button theme.
5+
*/
6+
7+
/* Generic button of medium size. */
8+
.button {
9+
align-items: center;
10+
background-image: linear-gradient(to top, lightgray, white 50%, white);
11+
border: solid 1px gray;
12+
border-radius: 3px;
13+
color: inherit;
14+
display: inline-flex;
15+
font: inherit;
16+
justify-content: center;
17+
min-height: 36px;
18+
margin: 6px;
19+
padding: 6px 24px;
20+
text-align: center;
21+
text-decoration: none;
22+
vertical-align: middle;
23+
24+
/* NOTE: All CSS rules below are nested to have higher specifity, thus
25+
* avoiding overriding of these rules by parent rules in some scenarious. */
26+
27+
/* Additional styling of disabled buttons. */
28+
&.disabled {
29+
cursor: not-allowed;
30+
opacity: 0.33;
31+
}
32+
33+
/* .link and .regular classes are applied only to active button-like links,
34+
* and real buttons (rendered as <button> elements). */
35+
&.link,
36+
&.regular {
37+
/* To prevent different styling of the button-like link once it has been
38+
* visited. */
39+
&:visited {
40+
color: inherit;
41+
}
42+
43+
&:focus {
44+
box-shadow: 0 0 3px 1px lightblue;
45+
border-color: blue;
46+
outline: none;
47+
}
48+
49+
&:hover {
50+
border-color: gray;
51+
cursor: pointer;
52+
}
53+
54+
&.active,
55+
&:active {
56+
background-image: linear-gradient(to bottom, lightgray, white 50%, white);
57+
box-shadow: inset 0 1px 3px 0 lightgray;
58+
border-color: gray;
59+
}
60+
}
61+
62+
&.xs {
63+
border-radius: 1px;
64+
min-height: 24px;
65+
padding: 1px 12px;
66+
}
67+
68+
&.sm {
69+
border-radius: 1px;
70+
min-height: 30px;
71+
padding: 3px 18px;
72+
}
73+
74+
&.lg {
75+
border-radius: 3px;
76+
min-height: 42px;
77+
padding: 9px 30px;
78+
}
79+
80+
&.xl {
81+
border-radius: 6px;
82+
min-height: 48px;
83+
padding: 12px 36px;
84+
}
85+
}

‎src/styles/global.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ html,
66
body {
77
text-rendering: geometricPrecision;
88
}
9+
10+
* {
11+
box-sizing: border-box;
12+
}

0 commit comments

Comments
 (0)
Please sign in to comment.