@prop-styles/vue
Version:
Process CSS-related properties in Props so that they can generate the element style.
188 lines (170 loc) • 4.66 kB
TypeScript
/*!
* @prop-styles/vue version 1.0.3-beta
* Author: Capricorncd<capricorncd@qq.com>
* Homepage: https://github.com/capricorncd/prop-styles#readme
* Released on: 2025-11-09 10:56:23 (GMT+0000)
*/
import type { Property } from 'csstype';
import type { ComputedRef, StyleValue } from 'vue';
export function createPropStyles<T extends BaseProps>(props: T, mappings?: PropMappings<T>, options?: CreatePropStylesOptions): Record<string, string>;
export function getDefaultBreakpoint(breakpoints?: boolean | Record<Breakpoint, number>): ;
export function transform(key: string, value: any, strValue?: string): ;
export function usePropStyles<T extends BaseProps>(props: T, mappings?: PropMappings<T>): UsePropStylesReturn;
export type BaseProps = BreakpointTransfer<OriginalBaseProps>;
export type BooleanValueKeys =
| 'flex'
| 'column'
| 'wrap'
| 'scroll'
| 'inline'
| 'breakWord'
| 'nowrap'
| 'shadow';
export type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
export type BreakpointObject<V> = Partial<Record<Breakpoint, V>> & {
// Shared default value used when a breakpoint isn't specified
default?: V;
};
export type BreakpointTransfer<T extends OriginalBaseProps> = {
[K in keyof T]: T[K] | BreakpointObject<T[K]>;
};
export type Breakpoints = Record<Breakpoint, number>;
export interface CreatePropStylesOptions {
breakpoint?: Breakpoint;
breakpoints?: boolean | Record<Breakpoint, number>;
}
export type OriginalBaseProps = {
// display
display?: Property.Display;
// width
width?: number | string;
// min-width
minWidth?: number | string;
// max-width
maxWidth?: number | string;
// height
height?: number | string;
// min-height
minHeight?: number | string;
// max-height
maxHeight?: number | string;
// inline
inline?: boolean;
// flex or display=flex
flex?: boolean | Property.Flex;
// flex/grid's gap
gap?: number | string;
// flex-direction
column?: boolean;
// flex-direction
fd?: Property.FlexDirection;
// align-items
ai?: Property.AlignItems;
// align-content
ac?: Property.AlignContent;
// justify-items
ji?: Property.JustifyItems;
// justify-content
jc?: Property.JustifyContent;
// flex-wrap
wrap?: boolean | Property.FlexWrap;
// white-space
ws?: Property.WhiteSpace;
// padding
p?: number | string;
// padding-top
pt?: number | string;
// padding-right
pr?: number | string;
// padding-bottom
pb?: number | string;
// padding-left
pl?: number | string;
// padding-inline
px?: number | string;
// padding-block
py?: number | string;
// margin
m?: number | string;
// margin-top
mt?: number | string;
// margin-right
mr?: number | string;
// margin-bottom
mb?: number | string;
// margin-left
ml?: number | string;
// margin-inline
mx?: number | string;
// margin-block
my?: number | string;
// border-radius
radius?: string | number;
// font-size
fs?: string | number;
// font-weight
fw?: Property.FontWeight;
// line-height
lh?: string | number;
// color
color?: string;
// background
bg?: Property.Background;
// background-size
bgs?: Property.BackgroundSize;
// background-origin
bgo?: Property.BackgroundOrigin;
// scroll direction
scroll?: boolean | 'x' | 'y';
// text
breakWord?: boolean;
// border, border-width, border-color
border?: string | number;
borderTop?: string | number;
borderRight?: string | number;
borderBottom?: string | number;
borderLeft?: string | number;
// grid-template-columns
gtc?: string | number;
// grid-template-rows
gtr?: string | number;
// text-align
ta?: Property.TextAlign;
// position
position?: Property.Position;
// top
top?: string | number;
// right
right?: string | number;
// bottom
bottom?: string | number;
// left
left?: string | number;
// z-index
zIndex?: Property.ZIndex;
// inset
inset?: string | number;
// transform
transform?: Property.Transform;
cursor?: Property.Cursor;
shadow?: boolean | Property.BoxShadow;
nowrap?: boolean;
whiteSpace?: Property.WhiteSpace;
// aspect-ratio
ratio?: Property.AspectRatio;
};
export type PropMappingHandler<T extends BaseProps> = (
value: any,
props: T
) => PropMappingHandlerReturn | PropMappingHandlerReturn[];
export type PropMappingHandlerReturn = { key: string; value: string } | null;
export type PropMappings<T extends BaseProps> = Partial<
Record<keyof T, PropMappingHandler<T>>
>;
export interface UsePropStylesReturn {
style: ComputedRef<StyleValue[]>;
}
export interface VueBaseProps extends BaseProps {
style?: StyleValue;
class?: any;
}