Skip to content

Commit e35a081

Browse files
feat: use tailwindcss with sass & styled-components
1 parent 30541c5 commit e35a081

19 files changed

+753
-83
lines changed

.babelrc

+12-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Latest stable ECMAScript features
55
"@babel/preset-env",
66
{
7-
"useBuiltIns": "entry",
7+
"useBuiltIns": false,
88
// Do not transform modules to CJS
99
"modules": false,
1010
"targets": {
@@ -20,15 +20,23 @@
2020
],
2121
"plugins": [
2222
["@babel/plugin-proposal-class-properties"],
23-
["@babel/plugin-transform-destructuring", { "useBuiltIns": true }],
24-
["@babel/plugin-proposal-object-rest-spread", { "useBuiltIns": true }],
23+
["@babel/plugin-transform-destructuring", {
24+
"useBuiltIns": true
25+
}],
26+
["@babel/plugin-proposal-object-rest-spread", {
27+
"useBuiltIns": true
28+
}],
2529
[
2630
// Polyfills the runtime needed for async/await and generators
2731
"@babel/plugin-transform-runtime",
2832
{
2933
"helpers": false,
3034
"regenerator": true
3135
}
32-
]
36+
],
37+
// Support for twin.macro
38+
"babel-plugin-macros",
39+
// https://git.io/JJUrL
40+
"@babel/plugin-transform-react-jsx"
3341
]
3442
}

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Abhijith Vijayan <[email protected]> (abhijithvijayan.in)
3+
Copyright (c) Abhijith Vijayan <[email protected]> (abhijithvijayan.in)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

babel-plugin-macros.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
twin: {
3+
preset: 'styled-components',
4+
config: './tailwind.config.js',
5+
autoCssProp: true, // This adds the css prop when it's needed
6+
},
7+
};

package.json

+12-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"yarn": ">= 1.0.0"
88
},
99
"repository": "https://github.com/abhijithvijayan/kutt-extension.git",
10-
"author": "abhijithvijayan <[email protected]>",
10+
"author": "abhijithvijayan <[email protected]>",
1111
"scripts": {
1212
"dev:chrome": "cross-env NODE_ENV=development cross-env TARGET_BROWSER=chrome webpack --watch",
1313
"dev:firefox": "cross-env NODE_ENV=development cross-env TARGET_BROWSER=firefox webpack --watch",
@@ -20,9 +20,7 @@
2020
"lint:fix": "eslint . --ext .ts,.tsx --fix"
2121
},
2222
"husky": {
23-
"hooks": {
24-
"pre-commit": "lint-staged"
25-
}
23+
"hooks": {}
2624
},
2725
"lint-staged": {
2826
"*.{ts,tsx}": [
@@ -46,11 +44,12 @@
4644
"formik": "^2.1.4",
4745
"lodash.isequal": "^4.5.0",
4846
"qrcode.react": "^1.0.0",
49-
"react": "^16.13.0",
47+
"react": "^16.13.1",
5048
"react-copy-to-clipboard": "^5.0.2",
51-
"react-dom": "^16.13.0",
49+
"react-dom": "^16.13.1",
50+
"styled-components": "^5.1.1",
51+
"twin.macro": "^1.4.1",
5252
"unicorn.log": "^1.7.0",
53-
"webext-base-css": "^1.0.0",
5453
"webextension-polyfill-ts": "^0.13.0"
5554
},
5655
"devDependencies": {
@@ -60,6 +59,7 @@
6059
"@babel/plugin-proposal-class-properties": "^7.8.3",
6160
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
6261
"@babel/plugin-transform-destructuring": "^7.8.8",
62+
"@babel/plugin-transform-react-jsx": "^7.10.4",
6363
"@babel/plugin-transform-runtime": "^7.8.3",
6464
"@babel/preset-env": "^7.8.7",
6565
"@babel/preset-react": "^7.8.3",
@@ -69,6 +69,7 @@
6969
"@types/react": "^16.9.23",
7070
"@types/react-copy-to-clipboard": "^4.3.0",
7171
"@types/react-dom": "^16.9.5",
72+
"@types/styled-components": "^5.1.0",
7273
"@types/webpack": "^4.41.7",
7374
"@typescript-eslint/eslint-plugin": "^2.28.0",
7475
"@typescript-eslint/parser": "^2.28.0",
@@ -97,6 +98,9 @@
9798
"postcss-loader": "^3.0.0",
9899
"prettier": "^2.0.4",
99100
"resolve-url-loader": "^3.1.1",
101+
"sass-extract": "^2.1.0",
102+
"sass-extract-js": "^0.4.0",
103+
"sass-extract-loader": "^1.1.0",
100104
"sass-loader": "^8.0.2",
101105
"terser-webpack-plugin": "^2.3.5",
102106
"typescript": "^3.8.3",
@@ -107,4 +111,4 @@
107111
"wext-manifest-webpack-plugin": "^1.1.1",
108112
"zip-webpack-plugin": "^3.0.0"
109113
}
110-
}
114+
}

source/Options/OptionsForm.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, {useEffect} from 'react';
2+
import 'twin.macro';
23
import {
34
withFormik,
45
Field,
@@ -72,7 +73,12 @@ const InnerForm: React.FC<FormikProps<OptionsFormValuesProperties>> = (
7273
component={TextField}
7374
label="API Key"
7475
/>
75-
<button type="submit" className="btn-primary" disabled={isSubmitting}>
76+
<button
77+
tw="bg-white text-gray-800 font-bold rounded border-b-2 border-green-500 hover:border-green-600 hover:bg-green-500 hover:text-white shadow-md py-2 px-6 inline-flex items-center"
78+
type="submit"
79+
disabled={isSubmitting}
80+
>
81+
<span tw="mr-2">Validate</span>
7682
{/* eslint-disable-next-line no-nested-ternary */}
7783
{isSubmitting ? (
7884
<Icon name="spinner" className="icon" />
@@ -83,7 +89,6 @@ const InnerForm: React.FC<FormikProps<OptionsFormValuesProperties>> = (
8389
) : (
8490
<Icon name="zap" className="icon" />
8591
)}
86-
Validate
8792
</button>
8893
</div>
8994

source/Options/index.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
import React from 'react';
1+
import {ThemeProvider} from 'styled-components';
22
import ReactDOM from 'react-dom';
3+
import React from 'react';
34

4-
import './styles.scss';
5+
// Common styles
6+
import '../styles/main.scss';
57

68
import Options from './Options';
79

8-
ReactDOM.render(<Options />, document.getElementById('options-root'));
10+
// eslint-disable-next-line import/no-webpack-loader-syntax, import/no-unresolved, @typescript-eslint/no-var-requires
11+
const theme = require('sass-extract-loader?{"plugins": ["sass-extract-js"]}!../styles/base/_variables.scss');
12+
// Require sass variables using sass-extract-loader and specify the plugin
13+
14+
ReactDOM.render(
15+
<ThemeProvider theme={theme}>
16+
<Options />
17+
</ThemeProvider>,
18+
document.getElementById('options-root')
19+
);

source/Options/styles.scss

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
@import "../styles/fonts";
2-
@import "../styles/reset";
3-
@import "../styles/variables";
4-
@import "../styles/components";
5-
6-
@import "~webext-base-css/webext-base.css";
1+
@import "../styles/base/fonts";
2+
@import "../styles/base/reset";
3+
@import "../styles/base/variables";
4+
@import "../styles/base/components";
75

86
body {
97
color: $black;

source/Popup/Header.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, {useState} from 'react';
2+
import 'twin.macro';
23

34
import Icon from '../components/Icon';
45
import messageUtil from '../util/mesageUtil';
@@ -100,7 +101,7 @@ const Header: React.FC<HeaderProperties> = ({
100101

101102
return (
102103
<>
103-
<header id="header">
104+
<header id="header" tw="p-4">
104105
<div className="logo__holder">
105106
<img src="assets/logo.png" alt="logo" />
106107
</div>

source/Popup/Popup.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Loader from '../components/Loader';
1212
import PopupForm from './PopupForm';
1313
import PopupHeader from './Header';
1414

15-
import './styles.scss';
1615
import {openExtOptionsPage, isValidUrl} from '../util/tabs';
1716

1817
type HostProperties = {

source/Popup/index.tsx

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
import {ThemeProvider} from 'styled-components';
12
import React from 'react';
23
import ReactDOM from 'react-dom';
34

5+
// Common styles
6+
import '../styles/main.scss';
7+
8+
import './styles.scss';
9+
410
import Popup from './Popup';
511

6-
ReactDOM.render(<Popup />, document.getElementById('popup-root'));
12+
// eslint-disable-next-line import/no-webpack-loader-syntax, import/no-unresolved, @typescript-eslint/no-var-requires
13+
const theme = require('sass-extract-loader?{"plugins": ["sass-extract-js"]}!../styles/base/_variables.scss');
14+
// Require sass variables using sass-extract-loader and specify the plugin
15+
16+
ReactDOM.render(
17+
<ThemeProvider theme={theme}>
18+
<Popup />
19+
</ThemeProvider>,
20+
document.getElementById('popup-root')
21+
);

source/Popup/styles.scss

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
@import "../styles/fonts";
2-
@import "../styles/reset";
3-
@import "../styles/variables";
4-
@import "../styles/components";
1+
@import "../styles/base/fonts";
2+
@import "../styles/base/reset";
3+
@import "../styles/base/variables";
4+
@import "../styles/base/components";
55

66
body {
77
color: $black;
88
}
99

1010

1111
#header {
12-
padding: 15px;
1312
display: flex;
1413
justify-content: space-between;
1514
align-items: center;

source/styles/_reset.scss

-22
This file was deleted.
File renamed without changes.
File renamed without changes.

source/styles/base/_reset.scss

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@import '~advanced-css-reset/dist/reset.css';
2+
3+
// Add your custom reset rules here
4+
5+
* {
6+
margin: 0;
7+
padding: 0;
8+
border: 0;
9+
outline: 0;
10+
}

source/styles/_variables.scss renamed to source/styles/base/_variables.scss

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ $grey-white: #f3f3f3;
55
$white: #ffffff;
66

77
// **** fonts ****
8-
$font-nunito: "Nunito",
9-
sans-serif;
8+
109

1110
// font weights
1211
$thin: 100;

source/styles/main.scss

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import '~tailwindcss/dist/base.min.css';
2+
3+
@import "base/fonts";
4+
@import "base/variables";
5+
@import "base/components";
6+
@import "base/reset";

tailwind.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
purge: [],
3+
theme: {
4+
extend: {},
5+
},
6+
variants: {},
7+
plugins: [],
8+
}

0 commit comments

Comments
 (0)