-
Notifications
You must be signed in to change notification settings - Fork 290
feat(colorPicker): new add colorPicker Component Full version available #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bc22a2b
feat(colorPicker): 'new add colorPicker Component'
ErKeLost 75ab168
feat(color-picker): 'compose可拆分函数'
ErKeLost b0bc07c
Bug(color-picker): '修复基础色块导致的文本颜色失效'
ErKeLost ea7c70e
fix(color-picker): '移除defaultTab修改tab属性'
ErKeLost 197d432
fix(color-picker): 'dotsize属性失效问题'
ErKeLost 4711e79
fix(color-picker): '修改ts类型 修改用户默认颜色'
ErKeLost 673ceb2
feat(color-picker): '修改文本颜色展示规则 优化ts'
ErKeLost cbeeab3
fix(color-picker): '移除substr API 新增展示历史颜色api'
ErKeLost 88b7937
feat(color-picker): '新增color-picker文档'
ErKeLost 818711b
bug(color-picker): '修复scroll滚动导致colorpicker位置错误问题'
ErKeLost cc32f3b
fix(color-picker): '优化动态修改alpha代码 优化ts 文档'
ErKeLost ab22783
fix(color-picker): '修复暗黑模式下teleport 背景颜色'
ErKeLost 870c2a2
Merge branch 'dev' of https://github.com/DevCloudFE/vue-devui into dev
ErKeLost 9d90802
bug(color-picker): '修复resize时picker位置错误问题'
ErKeLost File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
packages/devui-vue/devui/color-picker/__tests__/color-picker.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { ColorPicker } from '../index'; | ||
|
||
describe('color-picker test', () => { | ||
it('color-picker init render', async () => { | ||
// todo | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { App } from 'vue' | ||
import ColorPicker from './src/color-picker' | ||
|
||
ColorPicker.install = function (app: App): void { | ||
app.component(ColorPicker.name, ColorPicker) | ||
} | ||
|
||
export { ColorPicker } | ||
|
||
export default { | ||
title: 'ColorPicker 颜色选择器', | ||
category: '数据录入', | ||
status: '80%', // TODO: 组件若开发完成则填入"100%",并删除该注释 | ||
install(app: App): void { | ||
app.use(ColorPicker as any) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/devui-vue/devui/color-picker/src/color-picker-types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { PropType, ExtractPropTypes } from 'vue' | ||
export const colorPickerProps = { | ||
modelValue: { | ||
type: [Object, String] as PropType<string | number> | ||
}, | ||
mode: { | ||
type: String | ||
}, | ||
showAlpha: { | ||
type: Boolean, | ||
default: true | ||
}, | ||
dotSize: { | ||
type: Number, | ||
default: 15 | ||
}, | ||
swatches: { | ||
type: Array as PropType<string[]> | ||
}, | ||
showHistory: { | ||
type: Boolean, | ||
default: true | ||
} | ||
} as const | ||
|
||
export type ColorPickerProps = ExtractPropTypes<typeof colorPickerProps> |
77 changes: 77 additions & 0 deletions
77
packages/devui-vue/devui/color-picker/src/color-picker.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
@import '../../style/theme/color'; | ||
|
||
.devui-color-picker { | ||
position: relative; | ||
&-position { | ||
position: absolute; | ||
z-index: 9999; | ||
background-color: $devui-connected-overlay-bg; | ||
top: 0; | ||
} | ||
|
||
&-color-value { | ||
display: flex; | ||
position: absolute; | ||
z-index: 4; | ||
left: 50%; | ||
top: 50%; | ||
transform: translate(-50%, -50%); | ||
font-weight: bold; | ||
color: rgb(204, 15, 15); | ||
} | ||
|
||
&-container { | ||
padding: 3px; | ||
border: 1px solid rgb(224, 224, 230); | ||
border-radius: 3px; | ||
&-wrap { | ||
width: 100%; | ||
height: 26px; | ||
box-sizing: content-box; | ||
box-shadow: 3px 0 5px #00000014; | ||
position: relative; | ||
cursor: pointer; | ||
overflow: hidden; | ||
display: inline-block; | ||
vertical-align: middle; | ||
|
||
&-current-color { | ||
top: 0; | ||
right: 0; | ||
left: 0; | ||
position: absolute; | ||
z-index: 3; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
&-current-color-transparent { | ||
top: 0; | ||
right: 0; | ||
left: 0; | ||
overflow: hidden; | ||
padding: 3px; | ||
width: 100%; | ||
height: 100%; | ||
position: absolute; | ||
z-index: 2; | ||
} | ||
&-transparent { | ||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAIAAADZF8uwAAAAGUlEQVQYV2M4gwH+YwCGIasIUwhT25BVBADtzYNYrHvv4gAAAABJRU5ErkJggg==); | ||
background-repeat: repeat; | ||
} | ||
} | ||
} | ||
} | ||
|
||
.color-picker-transition-enter-from, | ||
.color-picker-transition-leave-to { | ||
opacity: 0; | ||
} | ||
.color-picker-transition-enter-to, | ||
.color-picker-transition-leave-from { | ||
opacity: 1; | ||
} | ||
.color-picker-transition-enter-active, | ||
.color-picker-transition-leave-active { | ||
transition: opacity 0.2s ease-in-out; | ||
} |
178 changes: 178 additions & 0 deletions
178
packages/devui-vue/devui/color-picker/src/color-picker.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
import { | ||
defineComponent, | ||
ref, | ||
computed, | ||
onMounted, | ||
watch, | ||
nextTick, | ||
provide, | ||
Teleport, | ||
unref, | ||
readonly, | ||
Transition | ||
} from 'vue' | ||
import { | ||
useReactive, | ||
colorPickerResize, | ||
isExhibitionColorPicker, | ||
changeColorValue | ||
} from './utils/composeable' | ||
import { colorPickerProps, ColorPickerProps } from './color-picker-types' | ||
import colorPanel from './components/color-picker-panel/color-picker-panel' | ||
import './color-picker.scss' | ||
import { parseColor, extractColor, RGBAtoCSS } from './utils/color-utils' | ||
import { ColorPickerColor } from './utils/color-utils-types' | ||
export default defineComponent({ | ||
name: 'DColorPicker', | ||
components: { | ||
colorPanel | ||
}, | ||
props: colorPickerProps, | ||
emits: ['update:modelValue'], | ||
setup(props: ColorPickerProps, { emit }) { | ||
const DEFAUTL_MODE = 'rgb' | ||
const provideData = { | ||
showAlpha: useReactive(() => props.showAlpha), | ||
swatches: useReactive(() => props.swatches), | ||
dotSize: useReactive(() => props.dotSize), | ||
showHistory: useReactive(() => props.showHistory) | ||
} | ||
provide('provideData', readonly(provideData)) | ||
const initialColor = ref(null) | ||
const colorCubeRef = ref<HTMLElement | null>() | ||
const pickerRef = ref<HTMLElement | null>() | ||
const containerRef = ref<HTMLElement | null>() | ||
const left = ref(0) | ||
const top = ref(0) | ||
const isChangeTextColor = ref(true) | ||
const showColorPicker = ref(false) | ||
const formItemText = ref(`${props.mode ?? DEFAUTL_MODE}`) | ||
const mode = ref(unref(props.mode)) | ||
onMounted(() => { | ||
// resize 响应式 colorpicker | ||
window.addEventListener('resize', resize) | ||
// 点击展示 colorpicker | ||
window.addEventListener('click', isExhibition) | ||
}) | ||
// ** computeds | ||
// colorpicker panel 组件位置 | ||
const colorPickerPostion = computed(() => { | ||
if (colorCubeRef.value) { | ||
return { | ||
transform: `translate(${left.value}px, ${top.value}px)` | ||
} | ||
} | ||
return null | ||
}) | ||
// 交互触发item 颜色 面板 动态修改alpha后要还原 alpha 2021.12.18 | ||
const tiggerColor = computed(() => { | ||
const currentColor = initialColor.value.rgba | ||
const trigger = { ...currentColor, a: props.showAlpha ? currentColor.a : 1 } | ||
return { | ||
backgroundColor: `${RGBAtoCSS(trigger)}` | ||
} | ||
}) | ||
// 交互面板 的value 值 动态展示 根据不同 type | ||
const formItemValue = computed(() => { | ||
return extractColor(initialColor.value, '', formItemText.value, props.showAlpha) | ||
}) | ||
// 动态 根据当前 透明度修改文本颜色 tips:根据不同 面板颜色 目前 不够优雅 | ||
const textColor = computed(() => { | ||
// 数字代表 hsv 中的value 值 纵轴 动态切换 文本颜色 | ||
return changeColorValue(initialColor.value, 0.5) | ||
}) | ||
// ** emits | ||
// 动态 交互面板 文本展示颜色 tips:根据不同 面板颜色 目前 不够优雅 | ||
function changeTextColor(value: boolean): void { | ||
isChangeTextColor.value = value | ||
} | ||
// 通过修改画板 颜色 修改 v-model 颜色 | ||
function changePaletteColor(colorMap: ColorPickerColor): void { | ||
updateUserColor(colorMap) | ||
} | ||
// 通过用户点击触发修改 交互面板 文本类型 | ||
function changeTextModeType(type: string): void { | ||
mode.value = type | ||
formItemText.value = type | ||
} | ||
|
||
// 初始化的时候 确定 colopicker位置 由于 pickerref 默认 为 undefined 所以监听 showcolorpicker | ||
watch( | ||
() => showColorPicker.value, | ||
(newValue) => { | ||
const textPalette = colorCubeRef.value?.getBoundingClientRect() | ||
newValue && | ||
nextTick(() => { | ||
pickerRef.value.style.transform = `translate(${textPalette.left + 'px'}, ${ | ||
textPalette.top + window.scrollY + textPalette.height + 'px' | ||
})` | ||
}) | ||
} | ||
) | ||
// 监听用户输入 2021.12.10 | ||
watch( | ||
() => props.modelValue, | ||
(newValue) => { | ||
// 全部转换成对象 | ||
updateUserColor(parseColor(newValue, initialColor.value)) | ||
}, | ||
{ immediate: true } | ||
) | ||
// 更新用户输入颜色 2021.12.10 | ||
function updateUserColor(color) { | ||
initialColor.value = color | ||
// 提取颜色 2021.12.10 | ||
const value = extractColor(initialColor.value, props.modelValue, mode.value, props.showAlpha) | ||
emit('update:modelValue', value) | ||
} | ||
function resize() { | ||
return colorPickerResize(colorCubeRef, top, left) | ||
} | ||
function isExhibition(event: Event) { | ||
return isExhibitionColorPicker(event, colorCubeRef, pickerRef, showColorPicker) | ||
} | ||
kagol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return () => { | ||
return ( | ||
<div class='devui-color-picker' ref={colorCubeRef}> | ||
<div class='devui-color-picker-container'> | ||
<div class='devui-color-picker-container-wrap'> | ||
<div | ||
class='devui-color-picker-container-wrap-current-color' | ||
style={tiggerColor.value} | ||
></div> | ||
<div | ||
class={[ | ||
'devui-color-picker-container-wrap-transparent', | ||
'devui-color-picker-container-wrap-current-color-transparent' | ||
]} | ||
></div> | ||
<div class='devui-color-picker-color-value'> | ||
<p style={textColor.value}>{formItemValue.value}</p> | ||
</div> | ||
</div> | ||
</div> | ||
<Teleport to='body'> | ||
<Transition name='color-picker-transition'> | ||
{showColorPicker.value ? ( | ||
<div | ||
ref={pickerRef} | ||
style={colorPickerPostion.value} | ||
class={['devui-color-picker-position']} | ||
> | ||
<color-panel | ||
v-model={initialColor.value} | ||
ref={containerRef} | ||
mode={mode.value} | ||
onChangeTextColor={changeTextColor} | ||
onChangePaletteColor={changePaletteColor} | ||
onChangeTextModeType={changeTextModeType} | ||
></color-panel> | ||
</div> | ||
) : null} | ||
</Transition> | ||
</Teleport> | ||
</div> | ||
) | ||
} | ||
} | ||
}) |
42 changes: 42 additions & 0 deletions
42
...es/devui-vue/devui/color-picker/src/components/color-alpha-slider/color-alpha-slider.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.devui-color-picker-alpha-slider { | ||
position: relative; | ||
margin-bottom: 15px; | ||
width: 100%; | ||
height: 14px; | ||
box-shadow: 2px 0 8px rgba(0, 0, 0, 0.08); | ||
border-radius: 15px; | ||
|
||
&.transparent { | ||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAIAAADZF8uwAAAAGUlEQVQYV2M4gwH+YwCGIasIUwhT25BVBADtzYNYrHvv4gAAAABJRU5ErkJggg==); | ||
background-repeat: repeat; | ||
} | ||
|
||
&__bar { | ||
position: relative; | ||
width: 100%; | ||
height: 100%; | ||
border-radius: 15px; | ||
|
||
&-pointer { | ||
position: absolute; | ||
width: 14px; | ||
height: 14px; | ||
} | ||
|
||
&-handle { | ||
width: 14px; | ||
height: 14px; | ||
border-radius: 6px; | ||
transform: translate(-7px, -2px); | ||
background-color: #f8f8f8; | ||
margin-top: 2px; | ||
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.37); | ||
cursor: pointer; | ||
|
||
&.vertical { | ||
transform: translate(0, -7px); | ||
margin-top: 0; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.