Skip to content
Docs
dot

dot

stable

유틸리티 문자열을 플랫폼별 스타일 오브젝트로 변환하는 핵심 함수

Import

import { dot } from '@hua-labs/dot';

Functions

dot

유틸리티 문자열을 파싱하여 대상 플랫폼에 맞는 스타일 오브젝트로 변환합니다. 반환 타입은 target 리터럴에 따라 자동으로 좁혀집니다.

Signature

// 웹 (기본)
function dot(input: string | undefined | null, options?: DotOptions): StyleObject

// 타입 좁힘 오버로드
function dot(input: string | undefined | null, options: DotOptions & { target: 'web' }): StyleObject
function dot(input: string | undefined | null, options: DotOptions & { target: 'native' }): RNStyleObject
function dot(input: string | undefined | null, options: DotOptions & { target: 'flutter' }): FlutterRecipe

Parameters

파라미터타입설명
input`string \undefined \null`공백 구분 유틸리티 문자열. null/undefined는 {} 반환
optionsDotOptions선택적 옵션

DotOptions

옵션타입기본값설명
darkbooleanfalsetrue이면 dark: 변형을 활성화
breakpointstringundefined활성 브레이크포인트 (예: 'md', 'lg'). 모바일 퍼스트 캐스케이드
target`'web' \'native' \'flutter'`'web'출력 플랫폼. 전역 createDotConfig({ runtime }) 설정을 덮어씁니다

Returns

  • target: 'web' (기본) → StyleObject — CSSProperties 호환 플랫 오브젝트
  • target: 'native' → RNStyleObject — React Native StyleSheet 호환 오브젝트
  • target: 'flutter' → FlutterRecipe — Flutter 위젯 컴포지션 구조체

Usage

import { dot } from '@hua-labs/dot';

// 기본 사용 (웹)
dot('p-4 flex items-center bg-primary-500 text-white rounded-lg');
// {
//   padding: '16px',
//   display: 'flex',
//   alignItems: 'center',
//   backgroundColor: '#3b82f6',
//   color: '#ffffff',
//   borderRadius: '8px',
// }

// 다크 모드
dot('bg-white dark:bg-gray-900 text-black dark:text-white', { dark: true });
// { backgroundColor: '#111827', color: '#ffffff' }

// 반응형 — 모바일 퍼스트 캐스케이드
dot('p-4 md:p-8 lg:p-12', { breakpoint: 'lg' });
// { padding: '48px' }  ← base(p-4) → md(p-8) → lg(p-12) 순으로 적용

// 반응형 + 다크 모드 조합
dot('bg-white md:bg-gray-100 dark:bg-gray-900 dark:md:bg-gray-800', {
  breakpoint: 'md',
  dark: true,
});
// { backgroundColor: '#1f2937' }

// React Native 대상
dot('p-4 rounded-lg shadow-lg rotate-45', { target: 'native' });
// {
//   padding: 16,
//   borderRadius: 8,
//   shadowColor: '#000000',
//   shadowOffset: { width: 0, height: 4 },
//   shadowOpacity: 0.1,
//   shadowRadius: 6,
//   elevation: 4,
//   transform: [{ rotate: '45deg' }],
// }

// Flutter 대상
import type { FlutterRecipe } from '@hua-labs/dot';

const recipe = dot('p-4 bg-blue-500 rounded-lg', { target: 'flutter' }) as FlutterRecipe;
// {
//   padding: { top: 16, right: 16, bottom: 16, left: 16 },
//   decoration: { color: '#3b82f6', borderRadius: { topLeft: 8, topRight: 8, bottomLeft: 8, bottomRight: 8 } },
// }
// Arbitrary values
dot('w-[300px] bg-[#ff0000] p-[2rem]');
// { width: '300px', backgroundColor: '#ff0000', padding: '2rem' }

// 투명도 수정자
dot('bg-primary-500/50 text-gray-900/80');
// { backgroundColor: 'rgb(59 130 246 / 0.5)', color: 'rgb(17 24 39 / 0.8)' }

// 음수 값
dot('-m-4 -translate-x-2');
// { margin: '-16px', transform: 'translateX(-8px)' }

// !important 수정자
dot('!p-4 !bg-white');
// { padding: '16px !important', backgroundColor: '#ffffff !important' }

// 그라디언트
dot('bg-gradient-to-r from-blue-500 via-purple-500 to-pink-500');
// { backgroundImage: 'linear-gradient(to right, #3b82f6, #a855f7, #ec4899)' }

// 링 + 쉐도우 조합 (하나의 boxShadow로 병합)
dot('ring-2 shadow-md');
// { boxShadow: '0 0 0 2px ..., 0 4px 6px -1px rgba(0,0,0,0.1)' }

// 커스텀 브레이크포인트
import { createDotConfig } from '@hua-labs/dot';
createDotConfig({ breakpoints: ['tablet', 'desktop'] });
dot('p-4 tablet:p-8', { breakpoint: 'tablet' });
// { padding: '32px' }

Notes

  • dot()은 상태 변형(hover:, focus:, active:)을 무시합니다. 상태 스타일이 필요하면 dotMap()을 사용하세요.
  • target을 createDotConfig({ runtime: 'native' })로 전역 설정하면 TypeScript 반환 타입은 여전히 StyleObject입니다. 타입 안전한 네이티브 사용을 위해서는 @hua-labs/dot/native 서브패스를 사용하세요.
  • 캐시는 target, breakpoint, dark 옵션을 포함한 전체 컨텍스트를 키로 사용하므로 동일한 입력도 옵션이 다르면 별도로 캐시됩니다.
  • 입력이 null, undefined, 또는 빈 문자열이면 {}를 반환합니다.