Skip to content

Commit 2c10486

Browse files
committed
feat: Provide minified styles (#44) ✨
* docs: Add documentation on how to use default styles with various approaches (webpack, CDN, other 📚 Fixes #42 * feat: Provide uncompressed and compressed assets ✨ Fixes #43
1 parent 66faa44 commit 2c10486

File tree

3 files changed

+58
-19
lines changed

3 files changed

+58
-19
lines changed

README.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ A lightweight and fast control to render a select component that can display hie
3838
- [data](#data)
3939
- [placeholderText](#placeholdertext)
4040
- [Styling and Customization](#styling-and-customization)
41-
- [With Bootstrap styles](#styling-and-customization)
42-
- [With Material Design styles](#styling-and-customization)
41+
- [Using default styles](#default-styles)
42+
- [Customizing with Bootstrap, Material Design styles](#customizing-styles)
4343
- [Performance](#performance)
4444
- [Search optimizations](#search-optimizations)
4545
- [Search debouncing](#search-debouncing)
@@ -196,7 +196,46 @@ The text to display as placeholder on the search box. Defaults to `Choose...`
196196

197197
## Styling and Customization
198198

199-
The component brings minimal styles for bare-bones functional rendering. It is kept purposefully minimal so that user can style/customize it completely to suit their needs. Checkout `/docs` folder for some examples.
199+
### Default styles
200+
201+
The component brings minimal styles for bare-bones functional rendering. It is kept purposefully minimal so that user can style/customize it completely to suit their needs.
202+
203+
#### Using WebPack
204+
205+
If you're using a bundler like webpack, make sure you configure webpack to import the default styles. To do so, simply add this rule to your webpack config:
206+
207+
```js
208+
// allow webpack to import/bundle styles from node_modules for this component
209+
module: {
210+
rules: [
211+
{
212+
test: /\.css$/,
213+
use: ExtractTextPlugin.extract({
214+
fallback: 'style-loader',
215+
use: [{
216+
loader: 'css-loader'
217+
}]
218+
}),
219+
include: /node_modules[/\\]react-dropdown-tree-select/
220+
}
221+
]
222+
}
223+
```
224+
225+
#### Using a CDN
226+
You can import and place a style link directly by referencing it from a CDN.
227+
228+
```html
229+
<link href="https://unpkg.com/react-dropdown-tree-select/dist/styles.css" rel="stylesheet">
230+
```
231+
232+
Note: Above example will always fetch the latest version. To fetch a specific version, use `https://unpkg.com/react-dropdown-tree-select@<version>/dist/styles.css`. Visit [unpkg.com](https://unpkg.com/#/) to see other options.
233+
234+
#### Using with other bundlers
235+
You can reference the files from `node_modules/react-dropdown-tree-select/dist/styles.css` to include in your own bundle via gulp or any other bundlers you have.
236+
237+
### Customizing styles
238+
Once you import default styles, it is easy to add/override the provided styles to match popular frameworks. Checkout `/docs` folder for some examples.
200239

201240
- [With Bootstrap](/docs/examples/bootstrap)
202241
- [With Material Design ](/docs/examples/material)

src/tree-node/action.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
33

4-
const Action = (props) => {
4+
const Action = props => {
55
const { title, className, text, onAction, actionData } = props
66

7-
const onClick = (e) => {
7+
const onClick = () => {
88
if (typeof onAction === 'function') {
99
onAction(actionData)
1010
}

webpack.config.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path')
22
const webpack = require('webpack')
33
const ExtractTextPlugin = require('extract-text-webpack-plugin')
4-
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
4+
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer')
55

66
module.exports = {
77
devtool: 'source-map',
@@ -34,14 +34,10 @@ module.exports = {
3434
'process.env.NODE_ENV': JSON.stringify('production')
3535
}),
3636
new ExtractTextPlugin('styles.css'),
37-
new webpack.optimize.UglifyJsPlugin({
38-
sourceMap: true,
39-
exclude: /node_modules/
40-
}),
41-
new BundleAnalyzerPlugin({
42-
analyzerMode: 'static',
43-
openAnalyzer: false
44-
})
37+
new webpack
38+
.optimize
39+
.UglifyJsPlugin({sourceMap: true, exclude: /node_modules/}),
40+
new BundleAnalyzerPlugin({analyzerMode: 'static', openAnalyzer: false})
4541
],
4642
module: {
4743
rules: [
@@ -54,12 +50,16 @@ module.exports = {
5450
{
5551
test: /\.css$/,
5652
use: ExtractTextPlugin.extract({
57-
use: {
58-
loader: 'css-loader',
59-
options: {
60-
localIdentName: 'react-dropdown-tree-select__[local]--[hash:base64:5]'
53+
use: [
54+
{
55+
loader: 'css-loader',
56+
options: {
57+
localIdentName: 'react-dropdown-tree-select__[local]--[hash:base64:5]',
58+
importLoaders: 1,
59+
minimize: true
60+
}
6161
}
62-
}
62+
]
6363
}),
6464
include: /src/,
6565
exclude: /node_modules/

0 commit comments

Comments
 (0)