Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 941f992

Browse files
authored
Merge pull request #201 from MatthewDorner/addTheme
feat(css): create a Theme to override Bootstrap colors
2 parents ca44203 + 5206931 commit 941f992

11 files changed

+82
-4
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tsdx.config.js

.storybook/webpack.config.js

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ module.exports = async ({ config, mode }) => {
1818
},
1919
],
2020
})
21+
config.module.rules.push({
22+
test: /\.s[ac]ss$/i,
23+
use: [
24+
// Creates `style` nodes from JS strings
25+
'style-loader',
26+
// Translates CSS into CommonJS
27+
'css-loader',
28+
// Compiles Sass to CSS
29+
'sass-loader',
30+
],
31+
})
2132
config.resolve.extensions = ['.ts', '.tsx', '.js', '.jsx']
2233
config.resolve.plugins = [new TsConfigPathsPlugin({})]
2334
config.plugins.push(

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@
8181
"@types/tinymce": "~4.5.23",
8282
"@typescript-eslint/eslint-plugin": "~2.15.0",
8383
"@typescript-eslint/parser": "~2.15.0",
84+
"autoprefixer": "~9.7.3",
8485
"awesome-typescript-loader": "~5.2.1",
8586
"babel-loader": "~8.0.6",
8687
"bootstrap": "~4.4.0",
8788
"commitizen": "~4.0.3",
8889
"commitlint-config-cz": "0.12.1",
8990
"coveralls": "~3.0.6",
9091
"cross-env": "~6.0.3",
92+
"cssnano": "~4.1.10",
9193
"cz-conventional-changelog": "~3.0.2",
9294
"enzyme": "~3.11.0",
9395
"enzyme-adapter-react-16": "~1.15.2",
@@ -103,12 +105,15 @@
103105
"husky": "~4.0.0",
104106
"jest-canvas-mock": "~2.2.0",
105107
"lint-staged": "~9.5.0",
108+
"node-sass": "~4.13.0",
106109
"prettier": "~1.19.1",
107110
"react": "~16.12.0",
108111
"react-bootstrap": "~1.0.0-beta.14",
109112
"react-docgen": "~5.1.0",
110113
"react-docgen-typescript-loader": "~3.6.0",
111114
"react-dom": "~16.12.0",
115+
"rollup-plugin-postcss": "~2.0.3",
116+
"sass-loader": "~8.0.0",
112117
"semantic-release": "~15.14.0",
113118
"sinon": "~8.0.1",
114119
"tsdx": "~0.12.0",
@@ -143,7 +148,7 @@
143148
"<rootDir>/__mocks__/matchMediaMock.js"
144149
],
145150
"moduleNameMapper": {
146-
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
151+
"\\.(css|scss|less)$": "<rootDir>/__mocks__/styleMock.js"
147152
}
148153
}
149154
}

scss/_variables.scss

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
$theme-colors: (
2+
"primary": #1abc9c,
3+
"secondary": #009b9e,
4+
"success": #273647,
5+
"warning": #ffc107,
6+
"danger": #dc3545,
7+
"info": #177db8,
8+
"light": #fdfffc,
9+
"dark": #011627
10+
);

scss/main.scss

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* Bootstrap overrides */
2+
3+
@import "./_variables";
4+
5+
/* Import bootstrap */
6+
7+
@import "node_modules/bootstrap/scss/bootstrap";
8+
9+
/* Other CSS Imports */
10+
11+
@import '../node_modules/react-toastify/dist/ReactToastify.min.css';

src/components/Toaster/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react'
22
import { ToastContainer, toast, Slide } from 'react-toastify'
33
import { ToastProps, ToasterProps } from './interfaces'
44
import { titleWithMessage, titleWithoutMessage } from './components'
5+
import './toaster.scss'
56

67
export const Toast: any = (
78
type: ToastProps['type'],

src/components/Toaster/toaster.scss

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@import "../../../scss/_variables";
2+
3+
div.Toastify__toast.Toastify__toast--error {
4+
background: map-get($theme-colors, error);
5+
}
6+
7+
div.Toastify__toast.Toastify__toast--info {
8+
background: map-get($theme-colors, info);
9+
}
10+
11+
div.Toastify__toast.Toastify__toast--success {
12+
background: map-get($theme-colors, success);
13+
}
14+
15+
div.Toastify__toast.Toastify__toast--warning {
16+
background: map-get($theme-colors, warning);
17+
}

src/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { library } from '@fortawesome/fontawesome-svg-core'
22
import { fas } from '@fortawesome/free-solid-svg-icons'
33

4+
import '../scss/main.scss'
5+
46
library.add(fas)
57
export * from './components/Toaster'
68
export * from './components/Spinner'

stories/textfield.stories.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import React from 'react'
33
import { storiesOf } from '@storybook/react'
44

55
import { TextField } from '../src'
6-
import 'bootstrap/dist/css/bootstrap.min.css'
76

87
storiesOf('TextField', module)
98
.addParameters({

stories/toaster.stories.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { storiesOf } from '@storybook/react'
44

55
import Button from 'react-bootstrap/Button'
66
import { Toast, Toaster } from '../src'
7-
import 'bootstrap/dist/css/bootstrap.min.css'
8-
import 'react-toastify/dist/ReactToastify.min.css'
97

108
storiesOf('Toaster', module)
119
.addParameters({

tsdx.config.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const postcss = require('rollup-plugin-postcss')
2+
const autoprefixer = require('autoprefixer')
3+
const cssnano = require('cssnano')
4+
5+
module.exports = {
6+
rollup(config, options) {
7+
config.plugins.push(
8+
postcss({
9+
plugins: [
10+
autoprefixer(),
11+
cssnano({
12+
preset: 'default',
13+
}),
14+
],
15+
inject: false,
16+
// only write out CSS for the first bundle (avoids pointless extra files):
17+
extract: !!options.writeMeta,
18+
modules: true,
19+
}),
20+
)
21+
return config
22+
},
23+
}

0 commit comments

Comments
 (0)