Skip to content

Commit

Permalink
hide gradient selection in color picker for text/border colors
Browse files Browse the repository at this point in the history
  • Loading branch information
raheeliftikhar5 committed Oct 25, 2024
1 parent bd028f3 commit dd50f07
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface ColorSelectProps {
dispatch?: (value: any) => void;
changeColor?: (value: any) => void;
presetColors?: string[];
allowGradient?: boolean;
}

export const ColorSelect = (props: ColorSelectProps) => {
Expand All @@ -31,9 +32,11 @@ export const ColorSelect = (props: ColorSelectProps) => {

const presetColors = useMemo(() => {
let colors = props.presetColors || [];
colors = colors.concat(gradientColors.slice(0, 16 - colors.length));
if (props.allowGradient) {
colors = colors.concat(gradientColors.slice(0, 16 - colors.length));
}
return colors;
}, [props.presetColors, selectedColor]);
}, [props.presetColors, selectedColor, props.allowGradient]);

const throttleChange = useCallback(
throttle((rgbaColor: string) => {
Expand Down Expand Up @@ -70,6 +73,7 @@ export const ColorSelect = (props: ColorSelectProps) => {
width={250}
height={160}
presets={presetColors}
$allowGradient={props.allowGradient}
/>
</PopoverContainer>
}
Expand Down Expand Up @@ -191,11 +195,14 @@ const ColorBlock = styled.div<{ $color: string }>`
overflow: hidden;
`;

const StyledColorPicker = styled(ColorPicker)`
const StyledColorPicker = styled(ColorPicker)<{$allowGradient?: boolean}>`
#rbgcp-wrapper > div:nth-child(2) > div:first-child > div:first-child {
${props => !props.$allowGradient && `visibility: hidden`};
}
#rbgcp-wrapper > div:last-child > div:last-child {
justify-content: flex-start !important;
gap: 3px;
> div {
border: 1px solid lightgray;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,10 @@ export default function ThemeSettingsSelector(props: ColorConfigProps) {
themeSettingKey !== "gridBgImageOrigin" && (
<div className="config-input">
<ColorSelect
changeColor={_.debounce(setColor, 500, {
leading: true,
trailing: true,
})}
changeColor={setColor}
color={color!}
trigger="hover"
allowGradient={themeSettingKey === 'canvas' || themeSettingKey === 'primarySurface'}
/>
<TacoInput
value={color}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ function AppCanvasSettingsModal(props: ChildrenInstance) {
})}
{gridBg.propertyView({
label: trans("style.background"),
allowGradient: true,
})}
{gridBgImage.propertyView({
label: trans("appSetting.gridBgImage"),
Expand Down
4 changes: 3 additions & 1 deletion client/packages/lowcoder/src/comps/controls/colorControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type PropertyViewParam = {
isDep?: boolean;
// auto-generated message?
depMsg?: string;
allowGradient?: boolean;
};

export class ColorControl extends ColorCodeControl {
Expand All @@ -95,7 +96,7 @@ function ColorItem(props: {
const inputRef = React.createRef<HTMLDivElement>();
const containerRef = React.createRef<HTMLDivElement>();

const currentThemeColors = useThemeColors();
const currentThemeColors = useThemeColors(param.allowGradient);

const input = propertyView.call(controlThis, {
placeholder: param.panelDefaultColor,
Expand Down Expand Up @@ -138,6 +139,7 @@ function ColorItem(props: {
<ColorSelect
dispatch={controlThis.dispatch}
color={param.panelDefaultColor || color || DEFAULT_COLOR}
allowGradient={param.allowGradient}
presetColors={currentThemeColors}
/>
<div style={{ display: "flex" }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ export function styleControl<T extends readonly SingleColorConfig[]>(
isDep: true,
depMsg:
depMsg,
allowGradient: config.name.includes('background'),
})}
</div>
);
Expand Down
5 changes: 4 additions & 1 deletion client/packages/lowcoder/src/util/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export function useMergeCompStyles(
type ColorKey = 'primary' | 'textDark' | 'textLight' | 'canvas' | 'primarySurface' | 'border';
type ColorKeys = ColorKey[];

export function useThemeColors() {
export function useThemeColors(allowGradient?: boolean) {
const currentTheme = useContext(ThemeContext)?.theme ?? {} as ThemeDetail;
const colorKeys: ColorKeys = ['primary', 'textDark', 'textLight', 'canvas', 'primarySurface', 'border'];

Expand All @@ -248,6 +248,9 @@ export function useThemeColors() {
colors.push(currentTheme[colorKey] ?? '');
}
})
if (!allowGradient) {
colors = colors.concat(constantColors);
}
return uniq(colors);
}, [
currentTheme,
Expand Down
12 changes: 12 additions & 0 deletions client/packages/lowcoder/src/util/styleUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ const getBackgroundStyle = (style: Record<string, string | undefined>) => {
`;
}

const getTextStyle = (color?: string) => {
return css`
${isValidColor(color) && `color: ${color};`}
${isValidGradient(color) && `
background-image: -webkit-${color};
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
`}
`;
}

export {
getBackgroundStyle,
getTextStyle,
}

0 comments on commit dd50f07

Please sign in to comment.