* Create a single button component
( variant: string, size: string, shape: string, disabled: boolean, loading: boolean, state: string, )
| 338 | * Create a single button component |
| 339 | */ |
| 340 | async function createButtonComponent( |
| 341 | variant: string, |
| 342 | size: string, |
| 343 | shape: string, |
| 344 | disabled: boolean, |
| 345 | loading: boolean, |
| 346 | state: string, |
| 347 | ): Promise<ComponentNode> { |
| 348 | const variantClasses = variantProp.classes[variant] || ""; |
| 349 | const sizeClasses = sizeProp.classes[size] || ""; |
| 350 | |
| 351 | // Parse styles from Tailwind classes |
| 352 | const variantStyles = parseTailwindClasses(variantClasses); |
| 353 | const sizeStyles = parseTailwindClasses(sizeClasses); |
| 354 | |
| 355 | // Create component |
| 356 | const component = figma.createComponent(); |
| 357 | component.name = |
| 358 | "variant=" + |
| 359 | variant + |
| 360 | ", size=" + |
| 361 | size + |
| 362 | ", shape=" + |
| 363 | shape + |
| 364 | ", disabled=" + |
| 365 | disabled + |
| 366 | ", loading=" + |
| 367 | loading + |
| 368 | ", state=" + |
| 369 | state; |
| 370 | |
| 371 | const isCompactShape = shape === "square" || shape === "circle"; |
| 372 | |
| 373 | // Configure auto-layout |
| 374 | component.layoutMode = "HORIZONTAL"; |
| 375 | component.primaryAxisAlignItems = "CENTER"; |
| 376 | component.counterAxisAlignItems = "CENTER"; |
| 377 | |
| 378 | if (isCompactShape) { |
| 379 | // Square/circle: fixed size, no padding |
| 380 | const buttonSize = |
| 381 | COMPACT_SIZE_MAP_LOCAL[size] || FALLBACK_VALUES.height.base; |
| 382 | component.primaryAxisSizingMode = "FIXED"; |
| 383 | component.counterAxisSizingMode = "FIXED"; |
| 384 | component.resize(buttonSize, buttonSize); |
| 385 | component.paddingLeft = 0; |
| 386 | component.paddingRight = 0; |
| 387 | } else { |
| 388 | // Base shape: hug contents with padding |
| 389 | component.primaryAxisSizingMode = "AUTO"; |
| 390 | component.counterAxisSizingMode = "FIXED"; |
| 391 | component.paddingLeft = |
| 392 | sizeStyles.paddingX || FALLBACK_VALUES.padding.horizontal; |
| 393 | component.paddingRight = |
| 394 | sizeStyles.paddingX || FALLBACK_VALUES.padding.horizontal; |
| 395 | component.resize(100, sizeStyles.height || FALLBACK_VALUES.height.base); |
| 396 | } |
| 397 |
no test coverage detected