Skip to content

Commit

Permalink
feat(design): add borderless support for Select (#2254)
Browse files Browse the repository at this point in the history
  • Loading branch information
jikkai committed May 16, 2024
1 parent c638477 commit c59b5a5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/design/src/components/select/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ export const SelectBasic = {
},
};

export const SelectBorderless = {
render() {
const [value, setValue] = useState('');

const options = [
{ label: 'Option 1', value: 'option1' },
{ label: 'Option 2', value: 'option2' },
{ label: 'Option 3', value: 'option3' },
];

function handleChange(value: string | number | boolean) {
setValue(value as string);
}

return <Select value={value} options={options} onChange={handleChange} borderless />;
},
};

export const SelectGroup = {
render() {
const [value, setValue] = useState('');
Expand Down
15 changes: 14 additions & 1 deletion packages/design/src/components/select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import RcSelect from 'rc-select';
import React, { useContext } from 'react';

import type { LabelInValueType } from 'rc-select/lib/Select';
import clsx from 'clsx';
import { ConfigContext } from '../config-provider/ConfigProvider';
import styles from './index.module.less';

Expand Down Expand Up @@ -47,11 +48,18 @@ export interface ISelectProps {

style?: React.CSSProperties;

/**
* Whether the borderless style is used
* @default false
*/
borderless?: boolean;

className?: string;
/**
* select mode
*/
mode?: 'combobox' | 'multiple' | 'tags' | undefined;

dropdownRender?: (
menu: React.ReactElement<any, string | React.JSXElementConstructor<any>>
) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
Expand All @@ -75,6 +83,7 @@ export function Select(props: ISelectProps) {
style,
className,
mode,
borderless = false,
dropdownRender,
labelRender,
open,
Expand All @@ -85,6 +94,10 @@ export function Select(props: ISelectProps) {

const { mountContainer } = useContext(ConfigContext);

const _className = clsx(className, {
[styles.selectBorderless]: borderless,
});

return mountContainer && (
<RcSelect
mode={mode}
Expand All @@ -96,7 +109,7 @@ export function Select(props: ISelectProps) {
suffixIcon={<MoreDownSingle />}
onChange={onChange}
style={style}
className={className}
className={_className}
dropdownRender={dropdownRender}
labelRender={labelRender}
open={open}
Expand Down
18 changes: 18 additions & 0 deletions packages/design/src/components/select/index.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@
.search-input-without-border();
}

&-borderless {
&:not(.@{select-prefix}-customize-input) {
.@{select-prefix}-selector {
border-color: transparent;
}
}

&.@{select-prefix} {
// =============== Focused ===============
&-focused,
&:hover {
.@{select-prefix}-selector {
border-color: transparent !important;
}
}
}
}

// ================ Icons ================
&-allow-clear {
&.@{select-prefix}-multiple .@{select-prefix}-selector {
Expand Down

0 comments on commit c59b5a5

Please sign in to comment.