需求
使用 QInput 选择颜色并预览。
利用 color picker,但只显示调色板,且调色板颜色为 Quasar 的 css variable 支持的所有颜色。
自定义调色板
颜色列表
首先,我们需要获取 Quasar 支持的颜色变量列表。这个在 quasar/dist/types/api/color.d.ts
中有定义:
// color.d.ts
export type BrandColor =
| "primary"
| "secondary"
| "accent"
| "dark"
| "positive"
| "negative"
| "info"
| "warning";
type Color =
| "red"
| "pink"
| "purple"
| "deep-purple"
| "indigo"
| "blue"
| "light-blue"
| "cyan"
| "teal"
| "green"
| "light-green"
| "lime"
| "yellow"
| "amber"
| "orange"
| "deep-orange"
| "brown"
| "grey"
| "blue-grey";
type ColorShade = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14;
type DetailedColor = `${Color}-${ColorShade}`;
export type NamedColor = LiteralUnion<
BrandColor | Color | DetailedColor | keyof CustomColors
>;
Original...About 5 min