Skip to content

Commit

Permalink
feat: use tailwindcss with sass & styled-components
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijithvijayan committed Jul 2, 2020
1 parent 30541c5 commit e35a081
Show file tree
Hide file tree
Showing 19 changed files with 753 additions and 83 deletions.
16 changes: 12 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Latest stable ECMAScript features
"@babel/preset-env",
{
"useBuiltIns": "entry",
"useBuiltIns": false,
// Do not transform modules to CJS
"modules": false,
"targets": {
Expand All @@ -20,15 +20,23 @@
],
"plugins": [
["@babel/plugin-proposal-class-properties"],
["@babel/plugin-transform-destructuring", { "useBuiltIns": true }],
["@babel/plugin-proposal-object-rest-spread", { "useBuiltIns": true }],
["@babel/plugin-transform-destructuring", {
"useBuiltIns": true
}],
["@babel/plugin-proposal-object-rest-spread", {
"useBuiltIns": true
}],
[
// Polyfills the runtime needed for async/await and generators
"@babel/plugin-transform-runtime",
{
"helpers": false,
"regenerator": true
}
]
],
// Support for twin.macro
"babel-plugin-macros",
// https://git.io/JJUrL
"@babel/plugin-transform-react-jsx"
]
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Abhijith Vijayan <[email protected]> (abhijithvijayan.in)
Copyright (c) Abhijith Vijayan <[email protected]> (abhijithvijayan.in)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 7 additions & 0 deletions babel-plugin-macros.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
twin: {
preset: 'styled-components',
config: './tailwind.config.js',
autoCssProp: true, // This adds the css prop when it's needed
},
};
20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"yarn": ">= 1.0.0"
},
"repository": "https://github.com/abhijithvijayan/kutt-extension.git",
"author": "abhijithvijayan <[email protected]>",
"author": "abhijithvijayan <[email protected]>",
"scripts": {
"dev:chrome": "cross-env NODE_ENV=development cross-env TARGET_BROWSER=chrome webpack --watch",
"dev:firefox": "cross-env NODE_ENV=development cross-env TARGET_BROWSER=firefox webpack --watch",
Expand All @@ -20,9 +20,7 @@
"lint:fix": "eslint . --ext .ts,.tsx --fix"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
"hooks": {}
},
"lint-staged": {
"*.{ts,tsx}": [
Expand All @@ -46,11 +44,12 @@
"formik": "^2.1.4",
"lodash.isequal": "^4.5.0",
"qrcode.react": "^1.0.0",
"react": "^16.13.0",
"react": "^16.13.1",
"react-copy-to-clipboard": "^5.0.2",
"react-dom": "^16.13.0",
"react-dom": "^16.13.1",
"styled-components": "^5.1.1",
"twin.macro": "^1.4.1",
"unicorn.log": "^1.7.0",
"webext-base-css": "^1.0.0",
"webextension-polyfill-ts": "^0.13.0"
},
"devDependencies": {
Expand All @@ -60,6 +59,7 @@
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
"@babel/plugin-transform-destructuring": "^7.8.8",
"@babel/plugin-transform-react-jsx": "^7.10.4",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.8.7",
"@babel/preset-react": "^7.8.3",
Expand All @@ -69,6 +69,7 @@
"@types/react": "^16.9.23",
"@types/react-copy-to-clipboard": "^4.3.0",
"@types/react-dom": "^16.9.5",
"@types/styled-components": "^5.1.0",
"@types/webpack": "^4.41.7",
"@typescript-eslint/eslint-plugin": "^2.28.0",
"@typescript-eslint/parser": "^2.28.0",
Expand Down Expand Up @@ -97,6 +98,9 @@
"postcss-loader": "^3.0.0",
"prettier": "^2.0.4",
"resolve-url-loader": "^3.1.1",
"sass-extract": "^2.1.0",
"sass-extract-js": "^0.4.0",
"sass-extract-loader": "^1.1.0",
"sass-loader": "^8.0.2",
"terser-webpack-plugin": "^2.3.5",
"typescript": "^3.8.3",
Expand All @@ -107,4 +111,4 @@
"wext-manifest-webpack-plugin": "^1.1.1",
"zip-webpack-plugin": "^3.0.0"
}
}
}
9 changes: 7 additions & 2 deletions source/Options/OptionsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useEffect} from 'react';
import 'twin.macro';
import {
withFormik,
Field,
Expand Down Expand Up @@ -72,7 +73,12 @@ const InnerForm: React.FC<FormikProps<OptionsFormValuesProperties>> = (
component={TextField}
label="API Key"
/>
<button type="submit" className="btn-primary" disabled={isSubmitting}>
<button
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"
type="submit"
disabled={isSubmitting}
>
<span tw="mr-2">Validate</span>
{/* eslint-disable-next-line no-nested-ternary */}
{isSubmitting ? (
<Icon name="spinner" className="icon" />
Expand All @@ -83,7 +89,6 @@ const InnerForm: React.FC<FormikProps<OptionsFormValuesProperties>> = (
) : (
<Icon name="zap" className="icon" />
)}
Validate
</button>
</div>

Expand Down
17 changes: 14 additions & 3 deletions source/Options/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import React from 'react';
import {ThemeProvider} from 'styled-components';
import ReactDOM from 'react-dom';
import React from 'react';

import './styles.scss';
// Common styles
import '../styles/main.scss';

import Options from './Options';

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

ReactDOM.render(
<ThemeProvider theme={theme}>
<Options />
</ThemeProvider>,
document.getElementById('options-root')
);
10 changes: 4 additions & 6 deletions source/Options/styles.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
@import "../styles/fonts";
@import "../styles/reset";
@import "../styles/variables";
@import "../styles/components";

@import "~webext-base-css/webext-base.css";
@import "../styles/base/fonts";
@import "../styles/base/reset";
@import "../styles/base/variables";
@import "../styles/base/components";

body {
color: $black;
Expand Down
3 changes: 2 additions & 1 deletion source/Popup/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useState} from 'react';
import 'twin.macro';

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

return (
<>
<header id="header">
<header id="header" tw="p-4">
<div className="logo__holder">
<img src="assets/logo.png" alt="logo" />
</div>
Expand Down
1 change: 0 additions & 1 deletion source/Popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Loader from '../components/Loader';
import PopupForm from './PopupForm';
import PopupHeader from './Header';

import './styles.scss';
import {openExtOptionsPage, isValidUrl} from '../util/tabs';

type HostProperties = {
Expand Down
17 changes: 16 additions & 1 deletion source/Popup/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import {ThemeProvider} from 'styled-components';
import React from 'react';
import ReactDOM from 'react-dom';

// Common styles
import '../styles/main.scss';

import './styles.scss';

import Popup from './Popup';

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

ReactDOM.render(
<ThemeProvider theme={theme}>
<Popup />
</ThemeProvider>,
document.getElementById('popup-root')
);
9 changes: 4 additions & 5 deletions source/Popup/styles.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
@import "../styles/fonts";
@import "../styles/reset";
@import "../styles/variables";
@import "../styles/components";
@import "../styles/base/fonts";
@import "../styles/base/reset";
@import "../styles/base/variables";
@import "../styles/base/components";

body {
color: $black;
}


#header {
padding: 15px;
display: flex;
justify-content: space-between;
align-items: center;
Expand Down
22 changes: 0 additions & 22 deletions source/styles/_reset.scss

This file was deleted.

File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions source/styles/base/_reset.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@import '~advanced-css-reset/dist/reset.css';

// Add your custom reset rules here

* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ $grey-white: #f3f3f3;
$white: #ffffff;

// **** fonts ****
$font-nunito: "Nunito",
sans-serif;


// font weights
$thin: 100;
Expand Down
6 changes: 6 additions & 0 deletions source/styles/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@import '~tailwindcss/dist/base.min.css';

@import "base/fonts";
@import "base/variables";
@import "base/components";
@import "base/reset";
8 changes: 8 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
purge: [],
theme: {
extend: {},
},
variants: {},
plugins: [],
}
Loading

0 comments on commit e35a081

Please sign in to comment.