Skip to content

Commit

Permalink
style(color-picker): update color-picker style
Browse files Browse the repository at this point in the history
  • Loading branch information
S-mohan committed Aug 4, 2022
1 parent 0d28363 commit 492d477
Show file tree
Hide file tree
Showing 11 changed files with 429 additions and 244 deletions.
1 change: 1 addition & 0 deletions src/color-picker/panel/alpha.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default defineComponent({
rail-style={this.railStyle}
max-value={100}
disabled={this.disabled}
type="alpha"
/>
);
},
Expand Down
3 changes: 2 additions & 1 deletion src/color-picker/panel/format/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export default defineComponent({
<div class={`${baseClassName}__format`}>
<div class={`${baseClassName}__format--item`}>
<t-select
autoWidth={true}
size="small"
class={`${baseClassName}__format-mode-select`}
{...selectInputProps}
popupProps={{
overlayClassName: `${baseClassName}__select-options`,
Expand Down
2 changes: 2 additions & 0 deletions src/color-picker/panel/format/inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export default defineComponent({
<t-input
{...inputProps}
align="center"
size="small"
disabled={this.disabled}
v-model={this.modelValues[config.key]}
maxlength={this.format === 'HEX' ? 9 : undefined}
Expand All @@ -162,6 +163,7 @@ export default defineComponent({
{...inputProps}
align="center"
theme="normal"
size="small"
disabled={this.disabled}
v-model={this.modelValues[config.key]}
title={this.modelValues[config.key]}
Expand Down
16 changes: 3 additions & 13 deletions src/color-picker/panel/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ export default defineComponent({
setup(props) {
const baseClassName = useBaseClassName();
const modeValue = ref(props.mode);
const handleClosePopup = () => {
props.togglePopup?.(false);
};
watch(
() => props.mode,
(v) => {
Expand All @@ -44,10 +41,12 @@ export default defineComponent({
return {
baseClassName,
modeValue,
handleClosePopup,
};
},
render() {
if (this.colorModes?.length === 1) {
return null;
}
const { baseClassName } = this;
return (
<div class={`${baseClassName}__head`}>
Expand All @@ -69,15 +68,6 @@ export default defineComponent({
</t-radio-group>
)}
</div>
{this.closeBtn ? (
<span
role="button"
class={[`${baseClassName}__icon`, `${baseClassName}__close`]}
onClick={this.handleClosePopup}
>
<close-icon />
</span>
) : null}
</div>
);
},
Expand Down
1 change: 1 addition & 0 deletions src/color-picker/panel/hue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default defineComponent({
value={this.color.hue}
handleChange={this.handleChange}
disabled={this.disabled}
type="hue"
/>
);
},
Expand Down
25 changes: 20 additions & 5 deletions src/color-picker/panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ export default defineComponent({
);
};

const isGradient = this.mode === 'linear-gradient';

return (
<div class={[`${baseClassName}__panel`, this.disabled ? statusClassNames.disabled : false]}>
<panel-header
Expand All @@ -335,14 +337,27 @@ export default defineComponent({
handleModeChange={this.handleModeChange}
/>
<div class={[`${baseClassName}__body`]}>
{this.mode === 'linear-gradient' ? (
{isGradient ? (
<linear-gradient color={this.color} disabled={this.disabled} handleChange={this.handleGradientChange} />
) : null}
<saturation-panel color={this.color} disabled={this.disabled} handleChange={this.handleSatAndValueChange} />
<hue-slider color={this.color} disabled={this.disabled} handleChange={this.handleHueChange} />
{this.enableAlpha ? (
<alpha-slider color={this.color} disabled={this.disabled} handleChange={this.handleAlphaChange} />
) : null}
<div class={[`${baseClassName}__sliders-wrapper`]}>
<div class={[`${baseClassName}__sliders`]}>
<hue-slider color={this.color} disabled={this.disabled} handleChange={this.handleHueChange} />
{this.enableAlpha ? (
<alpha-slider color={this.color} disabled={this.disabled} handleChange={this.handleAlphaChange} />
) : null}
</div>
<div class={[`${baseClassName}__sliders-preview`, `${baseClassName}--bg-alpha`]}>
<span
class={`${baseClassName}__sliders-preview-inner`}
style={{
background: isGradient ? this.color.linearGradient : this.color.rgba,
}}
/>
</div>
</div>

<format-panel
{...{
props: {
Expand Down
1 change: 1 addition & 0 deletions src/color-picker/panel/linear-gradient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export default defineComponent({
<div class={`${baseClassName}__gradient-degree`} title={`${degree}deg`}>
<t-input-number
theme="normal"
size="small"
min={0}
max={360}
step={1}
Expand Down
18 changes: 14 additions & 4 deletions src/color-picker/panel/slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export default defineComponent({
railStyle: {
type: Object as PropType<any>,
},
type: {
type: String as PropType<'hue' | 'alpha'>,
default: 'hue',
},
},
setup(props, { emit }) {
const baseClassName = useBaseClassName();
Expand Down Expand Up @@ -96,12 +100,18 @@ export default defineComponent({
},
render() {
const {
baseClassName, className, railStyle, styles,
baseClassName, className, railStyle, styles, type, color,
} = this;
const paddingStyle = {
background: `linear-gradient(90deg, rgba(0,0,0,.0) 0%, rgba(0,0,0,.0) 93%, ${color.rgb} 93%, ${color.rgb} 100%)`,
};
return (
<div class={[`${baseClassName}__slider`, className]} ref="refPanel">
<div class={`${baseClassName}__rail`} style={railStyle}></div>
<span class={[`${baseClassName}__thumb`]} role="slider" tabindex={0} ref="refThumb" style={styles}></span>
<div class={[`${baseClassName}__slider-wrapper`, `${baseClassName}__slider-wrapper--${type}-type`]}>
{type === 'alpha' && <div class={`${baseClassName}__slider-padding`} style={paddingStyle} />}
<div class={[`${baseClassName}__slider`, className]} ref="refPanel">
<div class={`${baseClassName}__rail`} style={railStyle}></div>
<span class={[`${baseClassName}__thumb`]} role="slider" tabindex={0} ref="refThumb" style={styles}></span>
</div>
</div>
);
},
Expand Down
Loading

0 comments on commit 492d477

Please sign in to comment.