Skip to content

Instantly share code, notes, and snippets.

@hekystyle
Last active January 6, 2022 10:10
Show Gist options
  • Select an option

  • Save hekystyle/78c76d4fc8ca15650569679ca7b31cb2 to your computer and use it in GitHub Desktop.

Select an option

Save hekystyle/78c76d4fc8ca15650569679ca7b31cb2 to your computer and use it in GitHub Desktop.
Extends Select from Ant design by suffix using styled components
import React, { VFC } from 'react';
import styled, { css } from 'styled-components';
import { Select as AntdSelect, SelectProps as AntdSelectProps } from 'antd';
import { SelectValue } from 'antd/lib/select';
export interface SelectProps extends AntdSelectProps<SelectValue> {
suffix?: React.ReactElement;
}
const StyledSelect = styled(AntdSelect)<SelectProps>`
.ant-select-selector {
${({ suffix }) =>
suffix &&
css`
border-radius: 4px 0px 0px 4px !important;
min-width: 85%;
`}
}
`;
export function Select(props: SelectProps): ReturnType<VFC> {
const { suffix } = props;
return (
<section style={{ display: 'flex' }}>
<StyledSelect {...props} />
{suffix}
</section>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment