From ee175e70fc0c86fe105e9f1c43f6a943b8d95904 Mon Sep 17 00:00:00 2001 From: Wang Sijie Date: Wed, 16 Mar 2022 15:55:15 +0800 Subject: [PATCH] feat(console): button with title and icon (#393) --- .../src/components/Button/index.module.scss | 12 +++++++++++ .../console/src/components/Button/index.tsx | 21 +++++++++++++++---- packages/console/src/icons/Search.tsx | 19 +++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 packages/console/src/icons/Search.tsx diff --git a/packages/console/src/components/Button/index.module.scss b/packages/console/src/components/Button/index.module.scss index de01b008a..b95c5dcad 100644 --- a/packages/console/src/components/Button/index.module.scss +++ b/packages/console/src/components/Button/index.module.scss @@ -7,11 +7,23 @@ font: var(--font-button); transition: background 0.2s ease-in-out; @include _.text-ellipsis; + display: flex; + align-items: center; &:not(:disabled) { cursor: pointer; } + .icon { + display: block; + width: 16px; + height: 16px; + + &:not(:last-child) { + margin-right: _.unit(2); + } + } + &.small { height: 30px; padding: 0 _.unit(3); diff --git a/packages/console/src/components/Button/index.tsx b/packages/console/src/components/Button/index.tsx index cd8166c35..1a490e48f 100644 --- a/packages/console/src/components/Button/index.tsx +++ b/packages/console/src/components/Button/index.tsx @@ -1,22 +1,34 @@ import { I18nKey } from '@logto/phrases'; import classNames from 'classnames'; -import React, { HTMLProps } from 'react'; +import React, { HTMLProps, ReactNode } from 'react'; import { useTranslation } from 'react-i18next'; import * as styles from './index.module.scss'; -export type Props = Omit, 'type' | 'size' | 'title'> & { +type BaseProps = Omit, 'type' | 'size' | 'title'> & { htmlType?: 'button' | 'submit' | 'reset'; - title: I18nKey; type?: 'primary' | 'danger' | 'outline' | 'plain' | 'default'; size?: 'small' | 'medium' | 'large'; }; +type TitleButtonProps = BaseProps & { + title: I18nKey; + icon?: ReactNode; +}; + +type IconButtonProps = BaseProps & { + title?: I18nKey; + icon: ReactNode; +}; + +export type Props = TitleButtonProps | IconButtonProps; + const Button = ({ htmlType = 'button', type = 'default', size = 'medium', title, + icon, ...rest }: Props) => { const { t } = useTranslation(); @@ -27,7 +39,8 @@ const Button = ({ type={htmlType} {...rest} > - {t(title)} + {icon && {icon}} + {title && {t(title)}} ); }; diff --git a/packages/console/src/icons/Search.tsx b/packages/console/src/icons/Search.tsx new file mode 100644 index 000000000..8e18c4049 --- /dev/null +++ b/packages/console/src/icons/Search.tsx @@ -0,0 +1,19 @@ +import React, { SVGProps } from 'react'; + +const Search = (props: SVGProps) => ( + + + +); + +export default Search;