Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/toyobayashi/vscode-color-picker


https://github.com/toyobayashi/vscode-color-picker

Last synced: 2 days ago
JSON representation

Awesome Lists containing this project

README

        

# vscode-color-picker

Demo: [https://toyobayashi.github.io/vscode-color-picker](https://toyobayashi.github.io/vscode-color-picker)

## Usage

### CDN

Pure JavaScript:

``` html

(function () {
var ColorPicker = vscodeColorPicker.ColorPicker;
var initialColor = '#aaa';
var color = ColorPicker.toColor(initialColor);
var picker = new ColorPicker(document.getElementById('container'), {
color: initialColor,
presentation: ColorPicker.formatColor(color, ColorPicker.ColorType.RGB)
});
picker.onColorChanged(function (color) {
picker.setPresentation(ColorPicker.formatColor(color, ColorPicker.ColorType.RGB));
});
})();

```

Vue:

``` html

(function () {
// Vue.component('VscodeColorPicker', VscodeColorPickerVue);
new Vue({
components: {
VscodeColorPicker: VscodeColorPickerVue
}
}).$mount('#app');
})();

```

### Webpack

Pure JavaScript:

``` js
import '@tybys/vscode-color-picker/lib/vscode-color-picker.css'
import { ColorPicker } from '@tybys/vscode-color-picker'
```

Vue:

``` vue



{{color}}

import '@tybys/vscode-color-picker/lib/vscode-color-picker.css'
import { ColorPicker } from '@tybys/vscode-color-picker'
import VscodeColorPicker from '@tybys/vscode-color-picker/lib/vue/index.js'

export default {
components: {
VscodeColorPicker
},
data () {
return {
color: '#aaa'
}
},
computed: {
presentation () {
return ColorPicker.formatColor(this.color, ColorPicker.ColorType.RGB)
}
},
methods: {
onColorChange (color) {
this.color = color
}
}
}

```

React:

``` jsx
import '@tybys/vscode-color-picker/lib/vscode-color-picker.css'
import { ColorPicker } from '@tybys/vscode-color-picker'
import VscodeColorPicker from '@tybys/vscode-color-picker/lib/react/index.js'
import React from 'react'
import ReactDOM from 'react-dom'

class App extends React.Component {
constructor (props) {
super(props)

const initialColor = '#aaa'
const color = ColorPicker.toColor(initialColor)
this.state = {
color: initialColor,
presentation: ColorPicker.formatColor(color, ColorPicker.ColorType.RGB)
}
this.onColorChange = this.onColorChange.bind(this)
}

render () {
return (



{this.state.color}

)
}

onColorChange (color) {
this.setState({
color,
presentation: ColorPicker.formatColor(color, ColorPicker.ColorType.RGB)
})
}
}

ReactDOM.render(, document.getElementById('app'))
```