Merge branch 'improve-ui-types' into 'develop'
Refactor UI library types See merge request soapbox-pub/soapbox!1814
This commit is contained in:
commit
76a8f43679
|
@ -1,12 +1,32 @@
|
||||||
import classNames from 'clsx';
|
import classNames from 'clsx';
|
||||||
|
|
||||||
type ButtonThemes = 'primary' | 'secondary' | 'tertiary' | 'accent' | 'danger' | 'transparent' | 'outline'
|
const themes = {
|
||||||
type ButtonSizes = 'sm' | 'md' | 'lg'
|
primary:
|
||||||
|
'bg-primary-500 hover:bg-primary-400 dark:hover:bg-primary-600 border-transparent focus:bg-primary-500 text-gray-100 focus:ring-primary-300',
|
||||||
|
secondary:
|
||||||
|
'border-transparent bg-primary-100 dark:bg-primary-800 hover:bg-primary-50 dark:hover:bg-primary-700 focus:bg-primary-100 dark:focus:bg-primary-800 text-primary-500 dark:text-primary-200',
|
||||||
|
tertiary:
|
||||||
|
'bg-transparent border-gray-400 dark:border-gray-800 hover:border-primary-300 dark:hover:border-primary-700 focus:border-primary-500 text-gray-900 dark:text-gray-100 focus:ring-primary-500',
|
||||||
|
accent: 'border-transparent bg-secondary-500 hover:bg-secondary-400 focus:bg-secondary-500 text-gray-100 focus:ring-secondary-300',
|
||||||
|
danger: 'border-transparent bg-danger-100 dark:bg-danger-900 text-danger-600 dark:text-danger-200 hover:bg-danger-600 hover:text-gray-100 dark:hover:text-gray-100 dark:hover:bg-danger-500 focus:bg-danger-800 dark:focus:bg-danger-600',
|
||||||
|
transparent: 'border-transparent text-gray-800 backdrop-blur-sm bg-white/75 hover:bg-white/80',
|
||||||
|
outline: 'border-gray-100 border-2 bg-transparent text-gray-100 hover:bg-white/10',
|
||||||
|
};
|
||||||
|
|
||||||
|
const sizes = {
|
||||||
|
xs: 'px-3 py-1 text-xs',
|
||||||
|
sm: 'px-3 py-1.5 text-xs leading-4',
|
||||||
|
md: 'px-4 py-2 text-sm',
|
||||||
|
lg: 'px-6 py-3 text-base',
|
||||||
|
};
|
||||||
|
|
||||||
|
type ButtonSizes = keyof typeof sizes
|
||||||
|
type ButtonThemes = keyof typeof themes
|
||||||
|
|
||||||
type IButtonStyles = {
|
type IButtonStyles = {
|
||||||
theme: ButtonThemes,
|
theme: ButtonThemes
|
||||||
block: boolean,
|
block: boolean
|
||||||
disabled: boolean,
|
disabled: boolean
|
||||||
size: ButtonSizes
|
size: ButtonSizes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,26 +37,6 @@ const useButtonStyles = ({
|
||||||
disabled,
|
disabled,
|
||||||
size,
|
size,
|
||||||
}: IButtonStyles) => {
|
}: IButtonStyles) => {
|
||||||
const themes = {
|
|
||||||
primary:
|
|
||||||
'bg-primary-500 hover:bg-primary-400 dark:hover:bg-primary-600 border-transparent focus:bg-primary-500 text-gray-100 focus:ring-primary-300',
|
|
||||||
secondary:
|
|
||||||
'border-transparent bg-primary-100 dark:bg-primary-800 hover:bg-primary-50 dark:hover:bg-primary-700 focus:bg-primary-100 dark:focus:bg-primary-800 text-primary-500 dark:text-primary-200',
|
|
||||||
tertiary:
|
|
||||||
'bg-transparent border-gray-400 dark:border-gray-800 hover:border-primary-300 dark:hover:border-primary-700 focus:border-primary-500 text-gray-900 dark:text-gray-100 focus:ring-primary-500',
|
|
||||||
accent: 'border-transparent bg-secondary-500 hover:bg-secondary-400 focus:bg-secondary-500 text-gray-100 focus:ring-secondary-300',
|
|
||||||
danger: 'border-transparent bg-danger-100 dark:bg-danger-900 text-danger-600 dark:text-danger-200 hover:bg-danger-600 hover:text-gray-100 dark:hover:text-gray-100 dark:hover:bg-danger-500 focus:bg-danger-800 dark:focus:bg-danger-600',
|
|
||||||
transparent: 'border-transparent text-gray-800 backdrop-blur-sm bg-white/75 hover:bg-white/80',
|
|
||||||
outline: 'border-gray-100 border-2 bg-transparent text-gray-100 hover:bg-white/10',
|
|
||||||
};
|
|
||||||
|
|
||||||
const sizes = {
|
|
||||||
xs: 'px-3 py-1 text-xs',
|
|
||||||
sm: 'px-3 py-1.5 text-xs leading-4',
|
|
||||||
md: 'px-4 py-2 text-sm',
|
|
||||||
lg: 'px-6 py-3 text-base',
|
|
||||||
};
|
|
||||||
|
|
||||||
const buttonStyle = classNames({
|
const buttonStyle = classNames({
|
||||||
'inline-flex items-center border font-medium rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 appearance-none transition-all': true,
|
'inline-flex items-center border font-medium rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 appearance-none transition-all': true,
|
||||||
'select-none disabled:opacity-75 disabled:cursor-default': disabled,
|
'select-none disabled:opacity-75 disabled:cursor-default': disabled,
|
||||||
|
|
|
@ -18,13 +18,13 @@ const messages = defineMessages({
|
||||||
|
|
||||||
interface ICard {
|
interface ICard {
|
||||||
/** The type of card. */
|
/** The type of card. */
|
||||||
variant?: 'default' | 'rounded',
|
variant?: 'default' | 'rounded'
|
||||||
/** Card size preset. */
|
/** Card size preset. */
|
||||||
size?: 'md' | 'lg' | 'xl',
|
size?: keyof typeof sizes
|
||||||
/** Extra classnames for the <div> element. */
|
/** Extra classnames for the <div> element. */
|
||||||
className?: string,
|
className?: string
|
||||||
/** Elements inside the card. */
|
/** Elements inside the card. */
|
||||||
children: React.ReactNode,
|
children: React.ReactNode
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An opaque backdrop to hold a collection of related elements. */
|
/** An opaque backdrop to hold a collection of related elements. */
|
||||||
|
|
|
@ -17,7 +17,7 @@ const alignItemsOptions = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const spaces = {
|
const spaces = {
|
||||||
'0.5': 'space-x-0.5',
|
[0.5]: 'space-x-0.5',
|
||||||
1: 'space-x-1',
|
1: 'space-x-1',
|
||||||
1.5: 'space-x-1.5',
|
1.5: 'space-x-1.5',
|
||||||
2: 'space-x-2',
|
2: 'space-x-2',
|
||||||
|
@ -29,21 +29,21 @@ const spaces = {
|
||||||
|
|
||||||
interface IHStack {
|
interface IHStack {
|
||||||
/** Vertical alignment of children. */
|
/** Vertical alignment of children. */
|
||||||
alignItems?: 'top' | 'bottom' | 'center' | 'start',
|
alignItems?: keyof typeof alignItemsOptions
|
||||||
/** Extra class names on the <div> element. */
|
/** Extra class names on the <div> element. */
|
||||||
className?: string,
|
className?: string
|
||||||
/** Children */
|
/** Children */
|
||||||
children?: React.ReactNode,
|
children?: React.ReactNode
|
||||||
/** Horizontal alignment of children. */
|
/** Horizontal alignment of children. */
|
||||||
justifyContent?: 'between' | 'center' | 'start' | 'end' | 'around',
|
justifyContent?: keyof typeof justifyContentOptions
|
||||||
/** Size of the gap between elements. */
|
/** Size of the gap between elements. */
|
||||||
space?: 0.5 | 1 | 1.5 | 2 | 3 | 4 | 6 | 8,
|
space?: keyof typeof spaces
|
||||||
/** Whether to let the flexbox grow. */
|
/** Whether to let the flexbox grow. */
|
||||||
grow?: boolean,
|
grow?: boolean
|
||||||
/** Extra CSS styles for the <div> */
|
/** Extra CSS styles for the <div> */
|
||||||
style?: React.CSSProperties
|
style?: React.CSSProperties
|
||||||
/** Whether to let the flexbox wrap onto multiple lines. */
|
/** Whether to let the flexbox wrap onto multiple lines. */
|
||||||
wrap?: boolean,
|
wrap?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Horizontal row of child elements. */
|
/** Horizontal row of child elements. */
|
||||||
|
|
|
@ -10,8 +10,6 @@ const messages = defineMessages({
|
||||||
confirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
|
confirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
|
||||||
});
|
});
|
||||||
|
|
||||||
type Widths = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl'
|
|
||||||
|
|
||||||
const widths = {
|
const widths = {
|
||||||
xs: 'max-w-xs',
|
xs: 'max-w-xs',
|
||||||
sm: 'max-w-sm',
|
sm: 'max-w-sm',
|
||||||
|
@ -51,7 +49,7 @@ interface IModal {
|
||||||
skipFocus?: boolean,
|
skipFocus?: boolean,
|
||||||
/** Title text for the modal. */
|
/** Title text for the modal. */
|
||||||
title?: React.ReactNode,
|
title?: React.ReactNode,
|
||||||
width?: Widths,
|
width?: keyof typeof widths,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Displays a modal dialog box. */
|
/** Displays a modal dialog box. */
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import classNames from 'clsx';
|
import classNames from 'clsx';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
type SIZES = 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 10
|
|
||||||
|
|
||||||
const spaces = {
|
const spaces = {
|
||||||
0: 'space-y-0',
|
0: 'space-y-0',
|
||||||
'0.5': 'space-y-0.5',
|
[0.5]: 'space-y-0.5',
|
||||||
1: 'space-y-1',
|
1: 'space-y-1',
|
||||||
'1.5': 'space-y-1.5',
|
[1.5]: 'space-y-1.5',
|
||||||
2: 'space-y-2',
|
2: 'space-y-2',
|
||||||
3: 'space-y-3',
|
3: 'space-y-3',
|
||||||
4: 'space-y-4',
|
4: 'space-y-4',
|
||||||
|
@ -25,15 +23,15 @@ const alignItemsOptions = {
|
||||||
|
|
||||||
interface IStack extends React.HTMLAttributes<HTMLDivElement> {
|
interface IStack extends React.HTMLAttributes<HTMLDivElement> {
|
||||||
/** Size of the gap between elements. */
|
/** Size of the gap between elements. */
|
||||||
space?: SIZES,
|
space?: keyof typeof spaces
|
||||||
/** Horizontal alignment of children. */
|
/** Horizontal alignment of children. */
|
||||||
alignItems?: 'center',
|
alignItems?: 'center'
|
||||||
/** Vertical alignment of children. */
|
/** Vertical alignment of children. */
|
||||||
justifyContent?: 'center',
|
justifyContent?: 'center'
|
||||||
/** Extra class names on the <div> element. */
|
/** Extra class names on the <div> element. */
|
||||||
className?: string,
|
className?: string
|
||||||
/** Whether to let the flexbox grow. */
|
/** Whether to let the flexbox grow. */
|
||||||
grow?: boolean,
|
grow?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Vertical stack of child elements. */
|
/** Vertical stack of child elements. */
|
||||||
|
|
|
@ -1,16 +1,6 @@
|
||||||
import classNames from 'clsx';
|
import classNames from 'clsx';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
type Themes = 'default' | 'danger' | 'primary' | 'muted' | 'subtle' | 'success' | 'inherit' | 'white'
|
|
||||||
type Weights = 'normal' | 'medium' | 'semibold' | 'bold'
|
|
||||||
export type Sizes = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl'
|
|
||||||
type Alignments = 'left' | 'center' | 'right'
|
|
||||||
type TrackingSizes = 'normal' | 'wide'
|
|
||||||
type TransformProperties = 'uppercase' | 'normal'
|
|
||||||
type Families = 'sans' | 'mono'
|
|
||||||
type Tags = 'abbr' | 'p' | 'span' | 'pre' | 'time' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'label'
|
|
||||||
type Directions = 'ltr' | 'rtl'
|
|
||||||
|
|
||||||
const themes = {
|
const themes = {
|
||||||
default: 'text-gray-900 dark:text-gray-100',
|
default: 'text-gray-900 dark:text-gray-100',
|
||||||
danger: 'text-danger-600',
|
danger: 'text-danger-600',
|
||||||
|
@ -60,15 +50,19 @@ const families = {
|
||||||
mono: 'font-mono',
|
mono: 'font-mono',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Sizes = keyof typeof sizes
|
||||||
|
type Tags = 'abbr' | 'p' | 'span' | 'pre' | 'time' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'label'
|
||||||
|
type Directions = 'ltr' | 'rtl'
|
||||||
|
|
||||||
interface IText extends Pick<React.HTMLAttributes<HTMLParagraphElement>, 'dangerouslySetInnerHTML'> {
|
interface IText extends Pick<React.HTMLAttributes<HTMLParagraphElement>, 'dangerouslySetInnerHTML'> {
|
||||||
/** How to align the text. */
|
/** How to align the text. */
|
||||||
align?: Alignments,
|
align?: keyof typeof alignments,
|
||||||
/** Extra class names for the outer element. */
|
/** Extra class names for the outer element. */
|
||||||
className?: string,
|
className?: string,
|
||||||
/** Text direction. */
|
/** Text direction. */
|
||||||
direction?: Directions,
|
direction?: Directions,
|
||||||
/** Typeface of the text. */
|
/** Typeface of the text. */
|
||||||
family?: Families,
|
family?: keyof typeof families,
|
||||||
/** The "for" attribute specifies which form element a label is bound to. */
|
/** The "for" attribute specifies which form element a label is bound to. */
|
||||||
htmlFor?: string,
|
htmlFor?: string,
|
||||||
/** Font size of the text. */
|
/** Font size of the text. */
|
||||||
|
@ -76,15 +70,15 @@ interface IText extends Pick<React.HTMLAttributes<HTMLParagraphElement>, 'danger
|
||||||
/** HTML element name of the outer element. */
|
/** HTML element name of the outer element. */
|
||||||
tag?: Tags,
|
tag?: Tags,
|
||||||
/** Theme for the text. */
|
/** Theme for the text. */
|
||||||
theme?: Themes,
|
theme?: keyof typeof themes,
|
||||||
/** Letter-spacing of the text. */
|
/** Letter-spacing of the text. */
|
||||||
tracking?: TrackingSizes,
|
tracking?: keyof typeof trackingSizes,
|
||||||
/** Transform (eg uppercase) for the text. */
|
/** Transform (eg uppercase) for the text. */
|
||||||
transform?: TransformProperties,
|
transform?: keyof typeof transformProperties,
|
||||||
/** Whether to truncate the text if its container is too small. */
|
/** Whether to truncate the text if its container is too small. */
|
||||||
truncate?: boolean,
|
truncate?: boolean,
|
||||||
/** Font weight of the text. */
|
/** Font weight of the text. */
|
||||||
weight?: Weights,
|
weight?: keyof typeof weights,
|
||||||
/** Tooltip title. */
|
/** Tooltip title. */
|
||||||
title?: string,
|
title?: string,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue