PromucFlow_constructor/app/client/src/constants/ThemeConstants.tsx
Valera Melnikov 8be4936ca0
chore: add color validation + native color picker (#25355)
## Description
1. Reduced the number of default colors. Because the amount of suggested
options was too much: very little difference between shades and
sometimes with hues too. By removing half of them, we allow builders
make better choices faster. The transparent color has also been removed.
2. Added validation of color values because HTML colors are remarkably
easy to get wrong, because they allow so many different values and now
we support and validate all these guys
    - `hex` - `#bada55`
    - `name` - `LightGoldenrodYellow`
    - `special name` - `currentColor`
    - `rgb` - `rgb(0 0 0)`
    - `rgba` - `rgba(0, 0, 0, .45)`
    - `hsl` - `hsl(4.71239rad, 60%, 70%)`
    - `hsla` - `hsla(180deg 100% 50% / .8)`
    - `hwb` - `hwb(180deg 0% 0% / 100%)`
    - `lab` - `lab(2000.1337% -8.6911 -159.131231 / .987189732)`
    - `lch` - `lch(54.292% 106.839 40.853)`
<img width="283" alt="Снимок экрана 2023-08-02 в 17 58 07"
src="https://github.com/appsmithorg/appsmith/assets/11555074/a8fef365-506d-432e-85ad-cdb550de1f60">
    
3. Added support for a Full color picker. Now we can easily switch
between modes and builders can easily choose any colors.
<img width="259" alt="Снимок экрана 2023-08-02 в 17 43 34"
src="https://github.com/appsmithorg/appsmith/assets/11555074/be09cd92-7c69-43eb-812a-0b1fe3ac9ef6">


#### PR fixes following issue(s)
Fixes  #22996

#### Media

https://www.loom.com/share/098e0116e49744e7b10689d4a18ab664?sid=15405577-160e-4b48-bfef-bc8dcfa97efe

#### Type of change
- New feature (non-breaking change which adds functionality)

## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [x] Manual
- [x] Jest
- [x] Cypress

## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed

---------

Co-authored-by: Valera Melnikov <melnikov.vv@greendatasoft.ru>
2023-08-07 11:55:10 +03:00

135 lines
2.7 KiB
TypeScript

import { invert } from "lodash";
/**
* mapping of tailwind colors
*
* NOTE: these are used in colorpicker
*/
export type TailwindColors = {
[key: string]: {
[key: string]: string;
};
};
export const TAILWIND_COLORS: TailwindColors = {
gray: {
100: "#f4f4f5",
300: "#d4d4d8",
500: "#71717a",
700: "#3f3f46",
900: "#18181b",
},
red: {
100: "#fee2e2",
300: "#fca5a5",
500: "#ef4444",
700: "#b91c1c",
900: "#7f1d1d",
},
yellow: {
100: "#fef9c3",
300: "#fde047",
500: "#eab308",
700: "#a16207",
900: "#713f12",
},
green: {
100: "#dcfce7",
300: "#86efac",
500: "#22c55e",
700: "#15803d",
900: "#14532d",
},
blue: {
100: "#dbeafe",
300: "#93c5fd",
500: "#3b82f6",
700: "#1d4ed8",
900: "#1e3a8a",
},
purple: {
100: "#f3e8ff",
300: "#d8b4fe",
500: "#a855f7",
700: "#7e22ce",
900: "#581c87",
},
pink: {
100: "#fce7f3",
300: "#f9a8d4",
500: "#ec4899",
700: "#be185d",
900: "#831843",
},
};
export const bindingPrefix = "appsmith.theme";
export const getThemePropertyBinding = (property: string) =>
`{{${bindingPrefix}.${property}}}`;
export const borderRadiusPropertyName = "borderRadius";
/**
* border radius options to be shown in property pane
*/
export const borderRadiusOptions: Record<string, string> = {
none: "0px",
M: "0.375rem",
L: "1.5rem",
};
export const invertedBorderRadiusOptions: Record<string, string> =
invert(borderRadiusOptions);
export const boxShadowPropertyName = "boxShadow";
/**
* box shadow options to be shown in property pane
*/
export const boxShadowOptions: Record<string, string> = {
none: "none",
S: "0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)",
M: "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",
L: "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)",
};
/**
* box shadow size mapping for the size name to displayed in property pane
*/
export const sizeMappings: Record<string, string> = {
S: "Small",
M: "Medium",
L: "Large",
};
export const invertedBoxShadowOptions: Record<string, string> =
invert(boxShadowOptions);
export const colorsPropertyName = "colors";
// Text sizes in theming
export const THEMEING_TEXT_SIZES = {
xs: "0.75rem",
sm: "0.875rem",
base: "1rem",
md: "1.125rem",
lg: "1.5rem",
xl: "1.875rem",
"2xl": "3rem",
"3xl": "3.75rem",
};
// Text sizes type
export type ThemingTextSizes = keyof typeof THEMEING_TEXT_SIZES;
// Theming borderRadius:
export const THEMING_BORDER_RADIUS = {
none: "0px",
rounded: "0.375rem",
circle: "9999px",
};
export const DEFAULT_BOXSHADOW = "none";