|
@@ -1,7 +1,11 @@
|
|
|
import { css, cx } from "@linaria/core";
|
|
|
-import { IconAddLine, IconClose } from "@queenjs/icons";
|
|
|
+import { IconClose } from "@queenjs/icons";
|
|
|
import { defineComponent } from "vue";
|
|
|
-import { any, array, bool, number } from "vue-types";
|
|
|
+import { any, array, bool, number, string } from "vue-types";
|
|
|
+
|
|
|
+// radial-gradient(circle at 50% 50%, rgb(255, 255, 255), rgb(0, 253, 3) 100%);
|
|
|
+// radial-gradient(red 10px, yellow 30%, #1e90ff 50%);
|
|
|
+// linear-gradient(70deg, blue, pink);
|
|
|
|
|
|
export type gradientColorType = {
|
|
|
deg?: number;
|
|
@@ -10,9 +14,6 @@ export type gradientColorType = {
|
|
|
};
|
|
|
|
|
|
export function formatColor(item: string | gradientColorType) {
|
|
|
- // radial-gradient(circle at 50% 50%, rgb(255, 255, 255), rgb(0, 253, 3) 100%);
|
|
|
- // radial-gradient(red 10px, yellow 30%, #1e90ff 50%);
|
|
|
- // linear-gradient(70deg, blue, pink);
|
|
|
if (typeof item == "string") {
|
|
|
return item;
|
|
|
} else if (item.type == "radial") {
|
|
@@ -27,53 +28,68 @@ export default defineComponent({
|
|
|
value: any<string | gradientColorType>().isRequired,
|
|
|
data: array<string | gradientColorType>().isRequired,
|
|
|
columns: number().def(5),
|
|
|
- showAdd: bool().def(false),
|
|
|
showDelete: bool().def(false),
|
|
|
min: number().def(2),
|
|
|
},
|
|
|
- emits: ["change", "delete"],
|
|
|
+ emits: ["change", "delete", "add"],
|
|
|
setup(props, { emit }) {
|
|
|
return () => {
|
|
|
- const { columns, value, showAdd, showDelete, min } = props;
|
|
|
+ const { columns, value, showDelete, min } = props;
|
|
|
const list = props.data;
|
|
|
const propsColor = formatColor(value);
|
|
|
return (
|
|
|
<div class={cx("grid gap-16px", `grid-cols-${columns}`)}>
|
|
|
{list.map((item: string | gradientColorType, index: number) => {
|
|
|
- // const thisColor = Color(color).object();
|
|
|
const thisColor = formatColor(item);
|
|
|
const active = thisColor === propsColor ? true : false;
|
|
|
-
|
|
|
return (
|
|
|
- <div class="relative" key={index}>
|
|
|
- <div
|
|
|
- class={cx(
|
|
|
- itemStyles,
|
|
|
- "h-38px rounded cursor-pointer",
|
|
|
- columns == 4 ? "w-52px" : "w-38px",
|
|
|
- active && "active"
|
|
|
- )}
|
|
|
- style={{ background: thisColor }}
|
|
|
- onClick={() => emit("change", item)}
|
|
|
- ></div>
|
|
|
- {showDelete && list.length > min && (
|
|
|
- <IconClose
|
|
|
- class="absolute -right-8px -top-8px p-2px bg-dark-50 bg-opacity-80 rounded-1/2 text-light-50 cursor-pointer"
|
|
|
- onClick={() => emit("delete", index)}
|
|
|
- />
|
|
|
- )}
|
|
|
- </div>
|
|
|
+ <ColorItem
|
|
|
+ key={index}
|
|
|
+ color={thisColor}
|
|
|
+ columns={columns}
|
|
|
+ active={active}
|
|
|
+ onDelete={() => emit("delete", index)}
|
|
|
+ showDelete={showDelete && list.length > min}
|
|
|
+ onChange={() => emit("change", item)}
|
|
|
+ />
|
|
|
);
|
|
|
})}
|
|
|
- {showAdd && (
|
|
|
- <div
|
|
|
- class="w-38px h-38px rounded cursor-pointer bg-[#3b3b3b] flex items-center justify-center transition hover:opacity-70"
|
|
|
- onClick={() => {
|
|
|
- //
|
|
|
- }}
|
|
|
- >
|
|
|
- <IconAddLine class="text-22px text-dark-300" />
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ };
|
|
|
+ },
|
|
|
+});
|
|
|
+
|
|
|
+export const ColorItem = defineComponent({
|
|
|
+ props: {
|
|
|
+ color: string(),
|
|
|
+ active: bool(),
|
|
|
+ columns: number().def(5),
|
|
|
+ showDelete: bool().def(false),
|
|
|
+ min: number().def(2),
|
|
|
+ },
|
|
|
+ emits: ["change", "delete"],
|
|
|
+ setup(props, { emit }) {
|
|
|
+ return () => {
|
|
|
+ const { active, color, columns, showDelete } = props;
|
|
|
+ return (
|
|
|
+ <div class="relative group">
|
|
|
+ <div
|
|
|
+ class={cx(
|
|
|
+ "h-38px rounded-2px cursor-pointer overflow-hidden",
|
|
|
+ itemStyles,
|
|
|
+ active && "active",
|
|
|
+ columns == 4 ? "w-52px" : "w-38px"
|
|
|
+ )}
|
|
|
+ onClick={() => emit("change")}
|
|
|
+ >
|
|
|
+ <div class="h-full w-full" style={{ background: color }}></div>
|
|
|
+ </div>
|
|
|
+ {showDelete && (
|
|
|
+ <IconClose
|
|
|
+ class="absolute z-10 -right-8px -top-8px p-2px bg-dark-50 bg-opacity-80 rounded-1/2 text-light-50 cursor-pointer transition opacity-0 group-hover:opacity-100"
|
|
|
+ onClick={() => emit("delete")}
|
|
|
+ />
|
|
|
)}
|
|
|
</div>
|
|
|
);
|
|
@@ -83,6 +99,24 @@ export default defineComponent({
|
|
|
|
|
|
const itemStyles = css`
|
|
|
position: relative;
|
|
|
+ background-color: #fff;
|
|
|
+ background-image: linear-gradient(
|
|
|
+ -45deg,
|
|
|
+ rgba(57, 76, 96, 0.15) 25%,
|
|
|
+ transparent 25%,
|
|
|
+ transparent 75%,
|
|
|
+ rgba(57, 76, 96, 0.15) 75%
|
|
|
+ ),
|
|
|
+ linear-gradient(
|
|
|
+ -45deg,
|
|
|
+ rgba(57, 76, 96, 0.15) 25%,
|
|
|
+ transparent 25%,
|
|
|
+ transparent 75%,
|
|
|
+ rgba(57, 76, 96, 0.15) 75%
|
|
|
+ );
|
|
|
+
|
|
|
+ background-position: 0 0, 6px 6px;
|
|
|
+ background-size: 12px 12px;
|
|
|
&:before {
|
|
|
border-radius: 4px;
|
|
|
bottom: 0;
|