🎨 styles: button with only icon

:%s
This commit is contained in:
lytrankieio123 2021-08-24 14:13:09 +07:00
parent ca16c0d605
commit 44b8cf4608
3 changed files with 36 additions and 16 deletions

View File

@ -17,6 +17,9 @@ export default function Home() {
</div> </div>
<ButtonCommon type='ghost' icon={<IconBuy />}>Button</ButtonCommon> <ButtonCommon type='ghost' icon={<IconBuy />}>Button</ButtonCommon>
<ButtonCommon type='light'><IconBuy /></ButtonCommon>
<ButtonCommon type='light' icon={<IconBuy />}/>
<ButtonCommon type='ghost' icon={<IconBuy />} size='large'/>
</> </>
) )
} }

View File

@ -11,6 +11,20 @@
cursor: not-allowed; cursor: not-allowed;
color: var(--disabled); color: var(--disabled);
} }
&:hover {
@apply shadow-md;
&:not(:disabled) {
filter: brightness(1.05);
}
}
&:focus {
outline: none;
filter: brightness(1.05);
}
&:focus-visible {
outline: 2px solid var(--text-active);
}
&.loading { &.loading {
&::before { &::before {
content: ""; content: "";
@ -24,20 +38,6 @@
margin-right: 0.8rem; margin-right: 0.8rem;
} }
} }
&:hover {
@apply shadow-md;
&:not(:disabled) {
filter: brightness(1.05);
}
}
&:focus {
outline: none;
filter: brightness(1.05);
}
&:focus-visible {
outline: 2px solid var(--text-active);
}
&.light { &.light {
@apply text-base bg-white; @apply text-base bg-white;
@ -60,8 +60,18 @@
} }
} }
&.onlyIcon {
padding: 0.8rem;
.icon {
margin: 0;
}
}
&.large { &.large {
padding: 3.2rem 4.8rem; padding: 3.2rem 4.8rem;
&.onlyIcon {
padding: 1.6rem;
}
&.loading { &.loading {
&::before { &::before {
width: 2.4rem; width: 2.4rem;
@ -70,6 +80,8 @@
} }
} }
&.preserve { &.preserve {
flex-direction: row-reverse; flex-direction: row-reverse;
.icon { .icon {
@ -79,6 +91,10 @@
.icon { .icon {
margin: 0 1.6rem 0 0; margin: 0 1.6rem 0 0;
}
.label,
.icon {
svg path { svg path {
fill: currentColor; fill: currentColor;
} }

View File

@ -13,8 +13,8 @@ interface Props {
onClick?: () => void, onClick?: () => void,
} }
const ButtonCommon = memo(({ type = 'primary', size = 'default', const ButtonCommon = memo(({ type = 'primary', size = 'default', loading = false, isIconSuffix = false,
icon, loading, disabled, isIconSuffix, children, onClick }: Props) => { icon, disabled, children, onClick }: Props) => {
return ( return (
<button className={classNames({ <button className={classNames({
[s.buttonCommon]: true, [s.buttonCommon]: true,
@ -22,6 +22,7 @@ const ButtonCommon = memo(({ type = 'primary', size = 'default',
[s[size]]: !!size, [s[size]]: !!size,
[s.loading]: loading, [s.loading]: loading,
[s.preserve]: isIconSuffix, [s.preserve]: isIconSuffix,
[s.onlyIcon]: icon && !children,
})} })}
disabled={disabled} disabled={disabled}
onClick={onClick} onClick={onClick}