Skip to content

Commit

Permalink
convert ugly playground to Tailwind (stimulus-use#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienpoly authored Dec 3, 2020
1 parent e8a9dbc commit 6b6d81e
Show file tree
Hide file tree
Showing 12 changed files with 1,025 additions and 170 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
"@babel/plugin-transform-runtime": "^7.11.5",
"@babel/preset-modules": "^0.1.4",
"agadoo": "^2.0.0",
"autoprefixer": "^10.0.4",
"babel-loader": "^8.1.0",
"chai": "^4.2.0",
"chai-dom": "^1.8.2",
"css-loader": "^5.0.1",
"cypress": "^5.4.0",
"html2js": "^0.2.0",
"intersection-observer": "^0.11.0",
Expand All @@ -55,11 +57,15 @@
"microbundle": "^0.12.3",
"mocha": "^8.1.3",
"np": "^6.5.0",
"postcss": "^8.1.10",
"postcss-loader": "^4.1.0",
"rimraf": "^3.0.2",
"sinon": "^9.0.3",
"sinon-chai": "^3.5.0",
"sourcemap": "^0.1.0",
"stimulus": "^1.1.1",
"style-loader": "^2.0.0",
"tailwindcss": "^2.0.1",
"ts-loader": "^8.0.3",
"typescript": "^3.9.7",
"webpack": "^4.44.1",
Expand Down
17 changes: 6 additions & 11 deletions playground/controllers/cart_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@ import { ApplicationController } from 'stimulus-use'

export default class extends ApplicationController {
static targets = ['counterView']
counter = 0

initialize() {
this.counter = this.data.has('counter') ? parseInt(this.data.get('counter')) : 0
}

refreshTotal(e) {
this.counter += e.detail.quantity
console.log(e.detail)
this.renderCounter()
}

renderCounter() {
this.counterViewTarget.classList.toggle('hidden', this.counter <= 0)
this.counterViewTarget.textContent = this.counter
}

set counter(value) {
this.data.set('counter', value)
this.renderCounter()
}

get counter() {
return parseInt(this.data.get('counter'))
}
}
10 changes: 7 additions & 3 deletions playground/controllers/idle_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ export default class extends Controller {

away(event) {
this.statusTarget.textContent = 'away'
this.isIdleTarget.textContent = this.isIdle
if (this.hasIsIdleTarget) {
this.isIdleTarget.textContent = this.isIdle
}
}

back(event) {
this.statusTarget.textContent = 'active'
this.isIdleTarget.textContent = this.isIdle
if (this.hasIsIdleTarget) {
this.isIdleTarget.textContent = this.isIdle
}
}

log(event) {
console.log("state changed", event)
console.log('state changed', event)
}
}
6 changes: 3 additions & 3 deletions playground/controllers/resize_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ export default class extends Controller {
static targets = ['width', 'height']

options = {
eventPrefix: 'card',
eventPrefix: 'card'
}

connect() {
useResize(this, this.options)
}

resize({ width, height }) {
this.widthTarget.textContent = width
this.heightTarget.textContent = height
this.widthTarget.textContent = Math.round(width)
this.heightTarget.textContent = Math.round(height)
}
}
3 changes: 3 additions & 0 deletions playground/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
673 changes: 549 additions & 124 deletions playground/index.html

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions playground/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ import { definitionsFromContext } from 'stimulus/webpack-helpers'
const application = Application.start()
const context = require.context('./controllers', true, /\.js$/)
application.load(definitionsFromContext(context))

import './index.css'
Binary file added playground/stimulus-use-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {}
}
}
31 changes: 31 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const defaultTheme = require('tailwindcss/defaultTheme')

module.exports = {
purge: [],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
colors: {
green: {
'50': '#f6fcf9',
'100': '#ecf8f3',
'200': '#d0eee0',
'300': '#b3e3cd',
'400': '#7bcea8',
'500': '#42b983',
'600': '#3ba776',
'700': '#328b62',
'800': '#286f4f',
'900': '#205b40'
}
},
fontFamily: {
sans: ['Inter var', ...defaultTheme.fontFamily.sans]
}
}
},
variants: {
extend: {}
},
plugins: []
}
29 changes: 17 additions & 12 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ const path = require('path')

module.exports = {
entry: {
bundle: './playground/index.js',
bundle: './playground/index.js'
},

output: {
filename: '[name].js',
path: path.resolve(__dirname, 'public'),
path: path.resolve(__dirname, 'public')
},

resolve: {
alias: {
'stimulus-use': path.resolve(__dirname, './dist/index.js'),
},
'stimulus-use': path.resolve(__dirname, './dist/index.js')
}
},

devServer: {
contentBase: './playground',
watchContentBase: true
},

devtool: 'source-map',
Expand All @@ -36,13 +37,17 @@ module.exports = {
[
'@babel/plugin-transform-runtime',
{
regenerator: true,
},
],
],
},
},
regenerator: true
}
]
]
}
}
},
],
},
{
test: /\.css$/,
use: ['style-loader', { loader: 'css-loader', options: { importLoaders: 1 } }, 'postcss-loader']
}
]
}
}
Loading

0 comments on commit 6b6d81e

Please sign in to comment.