Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@ $ yarn add vue-color-kit

## Options

| Name | Type | Default | Description |
| ------------------ | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- |
| theme | String | `dark` | `dark` or `light` |
| color | String | `#000000` | `rgba` or `hex` |
| colors-default | Array | `['#000000', '#FFFFFF', '#FF1900', '#F47365', '#FFB243', '#FFE623', '#6EFF2A', '#1BC7B1', '#00BEFF', '#2E81FF', '#5D61FF', '#FF89CF', '#FC3CAD', '#BF3DCE', '#8E00A7', 'rgba(0,0,0,0)']` | like `['#ff00ff', '#0f0f0f', ...]` |
| colors-history-key | String | `vue-color-kit-history` |
| sucker-hide | Boolean | `true` | `true` or `false` |
| sucker-canvas | HTMLCanvasElement | `null` | like `document.createElement('canvas')` |
| sucker-area | Array | `[]` | like `[x1, y1, x2, y2]` |
| Name | Type | Default | Description |
| ------------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| theme | String | `dark` | `dark` or `light` |
| color | String | `#000000` | `rgba` or `hex` |
| colors-default | Array | `['#000000', '#FFFFFF', '#FF1900', '#F47365', '#FFB243', '#FFE623', '#6EFF2A', '#1BC7B1', '#00BEFF', '#2E81FF', '#5D61FF', '#FF89CF', '#FC3CAD', '#BF3DCE', '#8E00A7', 'rgba(0,0,0,0)']` | like `['#ff00ff', '#0f0f0f', ...]` |
| colors-history-key | String | `vue-color-kit-history` |
| sucker-hide | Boolean | `true` | `true` or `false` |
| sucker-canvas | HTMLCanvasElement | `null` | like `document.createElement('canvas')` |
| sucker-area | Array | `[]` | like `[x1, y1, x2, y2]` |
| width | Number | 198 | any desired width |
| show-alpha | Boolean | `true` | `true` or `false` |
| disable-input-field | Boolean | `false` | `true` or `false`. It disable user from editting color value. |

> `color` is one-way data flow, so you can't use `v-model`. why? because you'll listen `changeColor` event do more things, so i think it's not necessary here.

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"lint:fix": "yarn run lint --write",
"test:types": "tsc --build tsconfig.json",
"test:unit": "jest --coverage",
"test": "yarn run test:types && yarn run test:unit && yarn run build && yarn run build:dts"
"test": "yarn run test:types && yarn run test:unit && yarn run build && yarn run build:dts",
"prepare": "yarn build"
},
"files": [
"dist/*.js",
Expand Down Expand Up @@ -61,6 +62,7 @@
"jest": "^26.5.3",
"lint-staged": "^10.5.1",
"mini-css-extract-plugin": "^1.6.0",
"node-sass": "^6.0.1",
"pascalcase": "^1.0.0",
"prettier": "^2.1.2",
"prismjs": "^1.22.0",
Expand Down
2 changes: 1 addition & 1 deletion src/color/Alpha.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default defineComponent({
})
</script>

<style lang="scss">
<style lang="scss" scoped>
.color-alpha {
position: relative;
margin-left: 8px;
Expand Down
8 changes: 6 additions & 2 deletions src/color/Box.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<span class="name">
{{ name }}
</span>
<input v-model="modelColor" class="value" />
<input :disabled="disableInputField" v-model="modelColor" class="value" />
</div>
</template>

Expand All @@ -20,6 +20,10 @@ export default defineComponent({
type: String,
default: '',
},
disableInputField: {
type: Boolean,
default: false,
},
},
emits: ['inputColor'],
setup(props, { emit }) {
Expand All @@ -38,7 +42,7 @@ export default defineComponent({
})
</script>

<style lang="scss">
<style lang="scss" scoped>
.color-type {
display: flex;
margin-top: 8px;
Expand Down
39 changes: 34 additions & 5 deletions src/color/ColorPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@selectHue="selectHue"
/>
<Alpha
v-if="showAlpha"
ref="alpha"
:color="rgbString"
:rgba="rgba"
Expand All @@ -42,8 +43,19 @@
@selectSucker="selectSucker"
/>
</div>
<Box name="HEX" :color="modelHex" @inputColor="inputHex" />
<Box name="RGBA" :color="modelRgba" @inputColor="inputRgba" />
<Box
name="HEX"
:disableInputField="disableInputField"
:color="modelHex"
@inputColor="inputHex"
/>
<Box
v-if="showAlpha"
name="RGBA"
:disableInputField="disableInputField"
:color="modelRgba"
@inputColor="inputRgba"
/>
<Colors
:color="rgbaString"
:colors-default="colorsDefault"
Expand Down Expand Up @@ -124,14 +136,26 @@ export default defineComponent({
type: String,
default: 'vue-colorpicker-history',
},
width: {
type: Number,
default: 198,
},
showAlpha: {
type: Boolean,
default: true,
},
disableInputField: {
type: Boolean,
default: false,
},
},
data() {
return {
hueWidth: 15,
hueHeight: 152,
previewHeight: 30,
modelRgba: '',
modelHex: '',
hueCount: this.showAlpha ? 2 : 1,
r: 0,
g: 0,
b: 0,
Expand All @@ -145,8 +169,13 @@ export default defineComponent({
isLightTheme(): boolean {
return this.theme === 'light'
},
hueHeight(): number {
//making hueHeight such that overall width equal to passed width
//20 is the sum of left and right padding of Color Picker
return this.width - ((this.hueWidth + 8) * this.hueCount + 20)
},
totalWidth(): number {
return this.hueHeight + (this.hueWidth + 8) * 2
return this.hueHeight + (this.hueWidth + 8) * this.hueCount
},
previewWidth(): number {
return this.totalWidth - (this.suckerHide ? 0 : this.previewHeight)
Expand Down Expand Up @@ -287,7 +316,7 @@ export default defineComponent({
})
</script>

<style lang="scss">
<style lang="scss" scoped>
.hu-color-picker {
padding: 10px;
background: #1d2024;
Expand Down
8 changes: 5 additions & 3 deletions src/color/Colors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ export default defineComponent({
},
})
</script>
<style lang="scss">
<style lang="scss" scoped>
.colors {
padding: 0;
margin: 0;
margin: 0.5rem 0 0 0;
display: flex;
gap: 0.44rem;
flex-wrap: wrap;
&.history {
margin-top: 10px;
border-top: 1px solid #2e333a;
Expand All @@ -105,7 +108,6 @@ export default defineComponent({
position: relative;
width: 16px;
height: 16px;
margin: 10px 0 0 10px;
border-radius: 3px;
box-sizing: border-box;
vertical-align: top;
Expand Down
2 changes: 1 addition & 1 deletion src/color/Hue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default defineComponent({
})
</script>

<style lang="scss">
<style lang="scss" scoped>
.hue {
position: relative;
margin-left: 8px;
Expand Down
2 changes: 1 addition & 1 deletion src/color/Saturation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default defineComponent({
})
</script>

<style lang="scss">
<style lang="scss" scoped>
.saturation {
position: relative;
cursor: pointer;
Expand Down
2 changes: 1 addition & 1 deletion src/color/Sucker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default defineComponent({
})
</script>

<style lang="scss">
<style lang="scss" scoped>
.sucker {
width: 30px;
fill: #9099a4;
Expand Down
Loading