Skip to content

Commit dd50f07

Browse files
hide gradient selection in color picker for text/border colors
1 parent bd028f3 commit dd50f07

File tree

7 files changed

+34
-10
lines changed

7 files changed

+34
-10
lines changed

client/packages/lowcoder-design/src/components/colorSelect/index.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface ColorSelectProps {
2121
dispatch?: (value: any) => void;
2222
changeColor?: (value: any) => void;
2323
presetColors?: string[];
24+
allowGradient?: boolean;
2425
}
2526

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

3233
const presetColors = useMemo(() => {
3334
let colors = props.presetColors || [];
34-
colors = colors.concat(gradientColors.slice(0, 16 - colors.length));
35+
if (props.allowGradient) {
36+
colors = colors.concat(gradientColors.slice(0, 16 - colors.length));
37+
}
3538
return colors;
36-
}, [props.presetColors, selectedColor]);
39+
}, [props.presetColors, selectedColor, props.allowGradient]);
3740

3841
const throttleChange = useCallback(
3942
throttle((rgbaColor: string) => {
@@ -70,6 +73,7 @@ export const ColorSelect = (props: ColorSelectProps) => {
7073
width={250}
7174
height={160}
7275
presets={presetColors}
76+
$allowGradient={props.allowGradient}
7377
/>
7478
</PopoverContainer>
7579
}
@@ -191,11 +195,14 @@ const ColorBlock = styled.div<{ $color: string }>`
191195
overflow: hidden;
192196
`;
193197

194-
const StyledColorPicker = styled(ColorPicker)`
198+
const StyledColorPicker = styled(ColorPicker)<{$allowGradient?: boolean}>`
199+
#rbgcp-wrapper > div:nth-child(2) > div:first-child > div:first-child {
200+
${props => !props.$allowGradient && `visibility: hidden`};
201+
}
195202
#rbgcp-wrapper > div:last-child > div:last-child {
196203
justify-content: flex-start !important;
197204
gap: 3px;
198-
205+
199206
> div {
200207
border: 1px solid lightgray;
201208
}

client/packages/lowcoder/src/components/ThemeSettingsSelector.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,10 @@ export default function ThemeSettingsSelector(props: ColorConfigProps) {
379379
themeSettingKey !== "gridBgImageOrigin" && (
380380
<div className="config-input">
381381
<ColorSelect
382-
changeColor={_.debounce(setColor, 500, {
383-
leading: true,
384-
trailing: true,
385-
})}
382+
changeColor={setColor}
386383
color={color!}
387384
trigger="hover"
385+
allowGradient={themeSettingKey === 'canvas' || themeSettingKey === 'primarySurface'}
388386
/>
389387
<TacoInput
390388
value={color}

client/packages/lowcoder/src/comps/comps/appSettingsComp.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ function AppCanvasSettingsModal(props: ChildrenInstance) {
477477
})}
478478
{gridBg.propertyView({
479479
label: trans("style.background"),
480+
allowGradient: true,
480481
})}
481482
{gridBgImage.propertyView({
482483
label: trans("appSetting.gridBgImage"),

client/packages/lowcoder/src/comps/controls/colorControl.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type PropertyViewParam = {
7373
isDep?: boolean;
7474
// auto-generated message?
7575
depMsg?: string;
76+
allowGradient?: boolean;
7677
};
7778

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

98-
const currentThemeColors = useThemeColors();
99+
const currentThemeColors = useThemeColors(param.allowGradient);
99100

100101
const input = propertyView.call(controlThis, {
101102
placeholder: param.panelDefaultColor,
@@ -138,6 +139,7 @@ function ColorItem(props: {
138139
<ColorSelect
139140
dispatch={controlThis.dispatch}
140141
color={param.panelDefaultColor || color || DEFAULT_COLOR}
142+
allowGradient={param.allowGradient}
141143
presetColors={currentThemeColors}
142144
/>
143145
<div style={{ display: "flex" }}>

client/packages/lowcoder/src/comps/controls/styleControl.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,7 @@ export function styleControl<T extends readonly SingleColorConfig[]>(
13651365
isDep: true,
13661366
depMsg:
13671367
depMsg,
1368+
allowGradient: config.name.includes('background'),
13681369
})}
13691370
</div>
13701371
);

client/packages/lowcoder/src/util/hooks.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export function useMergeCompStyles(
233233
type ColorKey = 'primary' | 'textDark' | 'textLight' | 'canvas' | 'primarySurface' | 'border';
234234
type ColorKeys = ColorKey[];
235235

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

@@ -248,6 +248,9 @@ export function useThemeColors() {
248248
colors.push(currentTheme[colorKey] ?? '');
249249
}
250250
})
251+
if (!allowGradient) {
252+
colors = colors.concat(constantColors);
253+
}
251254
return uniq(colors);
252255
}, [
253256
currentTheme,

client/packages/lowcoder/src/util/styleUtils.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ const getBackgroundStyle = (style: Record<string, string | undefined>) => {
1515
`;
1616
}
1717

18+
const getTextStyle = (color?: string) => {
19+
return css`
20+
${isValidColor(color) && `color: ${color};`}
21+
${isValidGradient(color) && `
22+
background-image: -webkit-${color};
23+
-webkit-background-clip: text;
24+
-webkit-text-fill-color: transparent;
25+
`}
26+
`;
27+
}
28+
1829
export {
1930
getBackgroundStyle,
31+
getTextStyle,
2032
}

0 commit comments

Comments
 (0)