mirror of
https://github.com/Lissy93/web-check.git
synced 2025-05-22 23:20:46 +02:00
Makes form components more customizable for easier reuse
This commit is contained in:
parent
c9c462f2a1
commit
b5e53a33b0
@ -8,6 +8,8 @@ interface ButtonProps {
|
|||||||
size?: InputSize,
|
size?: InputSize,
|
||||||
bgColor?: string,
|
bgColor?: string,
|
||||||
fgColor?: string,
|
fgColor?: string,
|
||||||
|
styles?: string,
|
||||||
|
title?: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledButton = styled.button<ButtonProps>`
|
const StyledButton = styled.button<ButtonProps>`
|
||||||
@ -31,16 +33,19 @@ const StyledButton = styled.button<ButtonProps>`
|
|||||||
${(props) => props.fgColor ?
|
${(props) => props.fgColor ?
|
||||||
`color: ${props.fgColor};` : `color: ${colors.background};`
|
`color: ${props.fgColor};` : `color: ${colors.background};`
|
||||||
}
|
}
|
||||||
|
${props => props.styles}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Button = (props: ButtonProps): JSX.Element => {
|
const Button = (props: ButtonProps): JSX.Element => {
|
||||||
const { children, size, bgColor, fgColor, onClick } = props;
|
const { children, size, bgColor, fgColor, onClick, styles, title } = props;
|
||||||
return (
|
return (
|
||||||
<StyledButton
|
<StyledButton
|
||||||
onClick={onClick || (() => null) }
|
onClick={onClick || (() => null) }
|
||||||
size={size}
|
size={size}
|
||||||
bgColor={bgColor}
|
bgColor={bgColor}
|
||||||
fgColor={fgColor}
|
fgColor={fgColor}
|
||||||
|
styles={styles}
|
||||||
|
title={title?.toString()}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
|
@ -3,24 +3,30 @@ import styled from 'styled-components';
|
|||||||
import ErrorBoundary from 'components/misc/ErrorBoundary';
|
import ErrorBoundary from 'components/misc/ErrorBoundary';
|
||||||
import Heading from 'components/Form/Heading';
|
import Heading from 'components/Form/Heading';
|
||||||
import colors from 'styles/colors';
|
import colors from 'styles/colors';
|
||||||
|
import { ReactNode } from 'react';
|
||||||
|
|
||||||
export const StyledCard = styled.section`
|
export const StyledCard = styled.section<{ styles?: string}>`
|
||||||
background: ${colors.backgroundLighter};
|
background: ${colors.backgroundLighter};
|
||||||
box-shadow: 4px 4px 0px ${colors.bgShadowColor};
|
box-shadow: 4px 4px 0px ${colors.bgShadowColor};
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
|
position: relative;
|
||||||
|
${props => props.styles}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
interface CardProps {
|
interface CardProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
heading?: string,
|
heading?: string,
|
||||||
|
styles?: string;
|
||||||
|
actionButtons?: ReactNode | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Card = (props: CardProps): JSX.Element => {
|
export const Card = (props: CardProps): JSX.Element => {
|
||||||
const { children, heading } = props;
|
const { children, heading, styles, actionButtons } = props;
|
||||||
return (
|
return (
|
||||||
<ErrorBoundary title={heading}>
|
<ErrorBoundary title={heading}>
|
||||||
<StyledCard>
|
<StyledCard styles={styles}>
|
||||||
|
{ actionButtons && actionButtons }
|
||||||
{ heading && <Heading as="h3" align="left" color={colors.primary}>{heading}</Heading> }
|
{ heading && <Heading as="h3" align="left" color={colors.primary}>{heading}</Heading> }
|
||||||
{children}
|
{children}
|
||||||
</StyledCard>
|
</StyledCard>
|
||||||
|
@ -10,6 +10,7 @@ export interface RowProps {
|
|||||||
children?: ReactNode,
|
children?: ReactNode,
|
||||||
rowList?: RowProps[],
|
rowList?: RowProps[],
|
||||||
title?: string,
|
title?: string,
|
||||||
|
open?: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const StyledRow = styled.div`
|
export const StyledRow = styled.div`
|
||||||
@ -79,12 +80,12 @@ const copyToClipboard = (text: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ExpandableRow = (props: RowProps) => {
|
export const ExpandableRow = (props: RowProps) => {
|
||||||
const { lbl, val, title, rowList } = props;
|
const { lbl, val, title, rowList, open } = props;
|
||||||
return (
|
return (
|
||||||
<Details>
|
<Details open={open}>
|
||||||
<StyledExpandableRow key={`${lbl}-${val}`}>
|
<StyledExpandableRow key={`${lbl}-${val}`}>
|
||||||
<span className="lbl" title={title}>{lbl}</span>
|
<span className="lbl" title={title?.toString()}>{lbl}</span>
|
||||||
<span className="val" title={val}>{val}</span>
|
<span className="val" title={val?.toString()}>{val}</span>
|
||||||
</StyledExpandableRow>
|
</StyledExpandableRow>
|
||||||
{ rowList &&
|
{ rowList &&
|
||||||
<SubRowList>
|
<SubRowList>
|
||||||
|
Loading…
Reference in New Issue
Block a user