mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-01 18:20:28 +00:00
Update button component
This commit is contained in:
@@ -1,30 +1,30 @@
|
|||||||
|
import { Spinner } from '..';
|
||||||
import { Wrapper } from './styles';
|
import { Wrapper } from './styles';
|
||||||
|
|
||||||
type ButtonProps = Omit<React.AllHTMLAttributes<HTMLButtonElement>, 'size'> & {
|
type ButtonProps = {
|
||||||
color:
|
color: 'client' | 'productOwner' | 'developer' | 'admin';
|
||||||
| 'client'
|
|
||||||
| 'productOwner'
|
|
||||||
| 'developer'
|
|
||||||
| 'admin'
|
|
||||||
| 'success'
|
|
||||||
| 'warning'
|
|
||||||
| 'error';
|
|
||||||
size?: 'small' | 'big';
|
size?: 'small' | 'big';
|
||||||
variant?: 'primary-action' | 'secondary-action' | 'outlined' | 'text';
|
variant?: 'primary-action' | 'secondary-action' | 'outlined' | 'text';
|
||||||
|
type?: 'submit' | 'button' | 'reset';
|
||||||
iconLeft?: React.SVGProps<SVGSVGElement>;
|
iconLeft?: React.SVGProps<SVGSVGElement>;
|
||||||
iconRight?: React.SVGProps<SVGSVGElement>;
|
iconRight?: React.SVGProps<SVGSVGElement>;
|
||||||
fullWidth?: boolean;
|
fullWidth?: boolean;
|
||||||
|
loading?: boolean;
|
||||||
|
disabled?: boolean;
|
||||||
text: string;
|
text: string;
|
||||||
onClick: () => void;
|
onClick?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Button = ({
|
const Button = ({
|
||||||
color,
|
color,
|
||||||
size = 'small',
|
size = 'small',
|
||||||
variant = 'text',
|
variant = 'text',
|
||||||
|
type = 'button',
|
||||||
iconLeft,
|
iconLeft,
|
||||||
iconRight,
|
iconRight,
|
||||||
fullWidth = false,
|
fullWidth = false,
|
||||||
|
loading = false,
|
||||||
|
disabled = false,
|
||||||
text,
|
text,
|
||||||
onClick,
|
onClick,
|
||||||
}: ButtonProps) => {
|
}: ButtonProps) => {
|
||||||
@@ -33,14 +33,22 @@ const Button = ({
|
|||||||
color={color}
|
color={color}
|
||||||
size={size}
|
size={size}
|
||||||
variant={variant}
|
variant={variant}
|
||||||
|
type={type}
|
||||||
iconLeft={iconLeft || undefined}
|
iconLeft={iconLeft || undefined}
|
||||||
iconRight={iconRight || undefined}
|
iconRight={iconRight || undefined}
|
||||||
fullWidth={fullWidth}
|
fullWidth={fullWidth}
|
||||||
|
loading={loading}
|
||||||
|
disabled={disabled}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
>
|
>
|
||||||
{iconLeft && <span className='icon left'>{iconLeft}</span>}
|
{iconLeft && <span className='icon left'>{iconLeft}</span>}
|
||||||
{text}
|
{text}
|
||||||
{iconRight && <span className='icon right'>{iconRight}</span>}
|
{iconRight && !loading && <span className='icon right'>{iconRight}</span>}
|
||||||
|
{loading && (
|
||||||
|
<span>
|
||||||
|
<Spinner color='white' />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,18 +1,13 @@
|
|||||||
import styled, { css } from 'styled-components';
|
import styled, { css } from 'styled-components';
|
||||||
|
|
||||||
type WrapperProps = {
|
type WrapperProps = {
|
||||||
color:
|
color: 'client' | 'productOwner' | 'developer' | 'admin';
|
||||||
| 'client'
|
|
||||||
| 'productOwner'
|
|
||||||
| 'developer'
|
|
||||||
| 'admin'
|
|
||||||
| 'success'
|
|
||||||
| 'warning'
|
|
||||||
| 'error';
|
|
||||||
size?: 'small' | 'big';
|
size?: 'small' | 'big';
|
||||||
variant?: 'primary-action' | 'secondary-action' | 'outlined' | 'text';
|
variant?: 'primary-action' | 'secondary-action' | 'outlined' | 'text';
|
||||||
iconLeft?: React.SVGProps<SVGSVGElement>;
|
iconLeft?: React.SVGProps<SVGSVGElement>;
|
||||||
iconRight?: React.SVGProps<SVGSVGElement>;
|
iconRight?: React.SVGProps<SVGSVGElement>;
|
||||||
|
loading?: boolean;
|
||||||
|
disabled?: boolean;
|
||||||
fullWidth?: boolean;
|
fullWidth?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -29,8 +24,8 @@ export const Wrapper = styled.button<WrapperProps>`
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
${({ iconLeft, iconRight }) => {
|
${({ iconLeft, iconRight, loading }) => {
|
||||||
if (iconLeft || iconRight)
|
if (iconLeft || iconRight || loading)
|
||||||
return css`
|
return css`
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
@@ -53,6 +48,12 @@ export const Wrapper = styled.button<WrapperProps>`
|
|||||||
margin-left: 0.5rem;
|
margin-left: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.lds-dual-ring {
|
||||||
|
display: inline !important;
|
||||||
|
|
||||||
|
border-width: 2px !important;
|
||||||
|
}
|
||||||
|
|
||||||
${({ size }) => {
|
${({ size }) => {
|
||||||
switch (size) {
|
switch (size) {
|
||||||
case 'small':
|
case 'small':
|
||||||
@@ -64,6 +65,16 @@ export const Wrapper = styled.button<WrapperProps>`
|
|||||||
width: 1rem;
|
width: 1rem;
|
||||||
height: 1rem;
|
height: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.lds-dual-ring {
|
||||||
|
width: 1rem !important;
|
||||||
|
height: 1rem !important;
|
||||||
|
|
||||||
|
&:after {
|
||||||
|
width: 0.5rem !important;
|
||||||
|
height: 0.5rem !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
case 'big':
|
case 'big':
|
||||||
return css`
|
return css`
|
||||||
@@ -74,6 +85,16 @@ export const Wrapper = styled.button<WrapperProps>`
|
|||||||
width: 1.25rem;
|
width: 1.25rem;
|
||||||
height: 1.25rem;
|
height: 1.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.lds-dual-ring {
|
||||||
|
width: 1.25rem !important;
|
||||||
|
height: 1.25rem !important;
|
||||||
|
|
||||||
|
&:after {
|
||||||
|
width: 0.75rem !important;
|
||||||
|
height: 0.75rem !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
default:
|
default:
|
||||||
return css`
|
return css`
|
||||||
@@ -84,6 +105,16 @@ export const Wrapper = styled.button<WrapperProps>`
|
|||||||
width: 1rem;
|
width: 1rem;
|
||||||
height: 1rem;
|
height: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.lds-dual-ring {
|
||||||
|
width: 1rem !important;
|
||||||
|
height: 1rem !important;
|
||||||
|
|
||||||
|
&:after {
|
||||||
|
width: 0.5rem !important;
|
||||||
|
height: 0.5rem !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@@ -98,13 +129,20 @@ export const Wrapper = styled.button<WrapperProps>`
|
|||||||
width: 1.25rem;
|
width: 1.25rem;
|
||||||
height: 1.25rem;
|
height: 1.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.lds-dual-ring {
|
||||||
|
width: 1.25rem;
|
||||||
|
height: 1.25rem;
|
||||||
|
}
|
||||||
`};
|
`};
|
||||||
|
|
||||||
${({ variant, color, theme }) => {
|
${({ variant, color, theme, disabled }) => {
|
||||||
switch (variant) {
|
switch (variant) {
|
||||||
case 'primary-action':
|
case 'primary-action':
|
||||||
return css`
|
return css`
|
||||||
background: ${theme.colors[color].main};
|
background: ${!disabled
|
||||||
|
? theme.colors[color].main
|
||||||
|
: theme.colors[color].light};
|
||||||
color: ${theme.colors.white.main};
|
color: ${theme.colors.white.main};
|
||||||
|
|
||||||
.icon svg path {
|
.icon svg path {
|
||||||
@@ -112,57 +150,82 @@ export const Wrapper = styled.button<WrapperProps>`
|
|||||||
}
|
}
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background: ${theme.colors[color].dark};
|
background: ${!disabled
|
||||||
|
? theme.colors[color].dark
|
||||||
|
: theme.colors[color].light};
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
case 'secondary-action':
|
case 'secondary-action':
|
||||||
return css`
|
return css`
|
||||||
background: ${theme.colors[color].light};
|
background: ${theme.colors[color].light};
|
||||||
color: #262628;
|
color: ${!disabled ? '#262628' : theme.colors[color].light};
|
||||||
|
|
||||||
.icon svg path {
|
.icon svg path {
|
||||||
stroke: #262628;
|
stroke: ${!disabled ? '#262628' : theme.colors[color].light};
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
case 'outlined':
|
case 'outlined':
|
||||||
return css`
|
return css`
|
||||||
background: none;
|
background: none;
|
||||||
color: ${theme.colors[color].main};
|
color: ${!disabled
|
||||||
border: 2px solid ${theme.colors[color].main};
|
? theme.colors[color].main
|
||||||
|
: theme.colors[color].light};
|
||||||
|
border: 2px solid
|
||||||
|
${!disabled ? theme.colors[color].main : theme.colors[color].light};
|
||||||
|
|
||||||
.icon svg path {
|
.icon svg path {
|
||||||
stroke: ${theme.colors[color].main};
|
stroke: ${!disabled
|
||||||
|
? theme.colors[color].main
|
||||||
|
: theme.colors[color].light};
|
||||||
}
|
}
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background: ${theme.colors[color].main};
|
background: ${!disabled ? theme.colors[color].main : 'none'};
|
||||||
color: ${theme.colors.white.main};
|
color: ${!disabled
|
||||||
|
? theme.colors.white.main
|
||||||
|
: theme.colors[color].light};
|
||||||
|
|
||||||
.icon svg path {
|
.icon svg path {
|
||||||
stroke: ${theme.colors.white.main};
|
stroke: ${!disabled
|
||||||
|
? theme.colors.white.main
|
||||||
|
: theme.colors[color].light};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
case 'text':
|
case 'text':
|
||||||
return css`
|
return css`
|
||||||
background: none;
|
background: none;
|
||||||
color: ${theme.colors[color].main};
|
color: ${!disabled
|
||||||
|
? theme.colors[color].main
|
||||||
|
: theme.colors[color].light};
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
.icon svg path {
|
.icon svg path {
|
||||||
stroke: ${theme.colors[color].main};
|
stroke: ${!disabled
|
||||||
|
? theme.colors[color].main
|
||||||
|
: theme.colors[color].light};
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
default:
|
default:
|
||||||
return css`
|
return css`
|
||||||
background: none;
|
background: none;
|
||||||
color: ${theme.colors[color].main};
|
color: ${!disabled
|
||||||
|
? theme.colors[color].main
|
||||||
|
: theme.colors[color].light};
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
.icon svg path {
|
.icon svg path {
|
||||||
stroke: ${theme.colors[color].main};
|
stroke: ${!disabled
|
||||||
|
? theme.colors[color].main
|
||||||
|
: theme.colors[color].light};
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
${({ disabled }) =>
|
||||||
|
disabled &&
|
||||||
|
css`
|
||||||
|
cursor: default;
|
||||||
|
`}
|
||||||
`;
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user