Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | 72x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 75x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 75x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 75x 75x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 75x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 75x 3x 3x 3x 3x 3x 3x 3x 3x 75x 3x 3x 3x 3x 3x 3x 3x 3x 75x 75x 66x 66x 66x 66x 66x 66x 66x 66x 75x 1x 1x 1x 1x 1x 1x 1x 1x 1x 75x 6x 6x 75x 4x 4x 65x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 75x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 75x 1x 1x 74x 74x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 73x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /** * FzButton - Versatile button component with multiple variants and environment-based sizing * * A comprehensive button component supporting five visual variants (primary, secondary, invisible, * danger, success) and two environment-based sizes (backoffice, frontoffice). Features * include icon integration, multiple interactive states, and full accessibility support. * * @example Basic usage (frontoffice default) * ```vue * <FzButton label="Click me" /> * ``` * * @example Backoffice environment * ```vue * <FzButton environment="backoffice" label="Save" /> * ``` * * @example With icon * ```vue * <FzButton label="Save" iconName="save" iconPosition="before" /> * ``` * * @example Danger variant * ```vue * <FzButton variant="danger" label="Delete" :disabled="!confirmed" /> * ``` */ <script lang="ts" setup> import { computed, useSlots, watch } from 'vue' import { FzIcon } from '@fiscozen/icons' import type { FzButtonProps, ButtonEnvironment } from './types' import { sizeToEnvironmentMapping } from './utils' const props = withDefaults( defineProps<FzButtonProps>(), { variant: 'primary', disabled: false, iconPosition: 'before', // Note: environment has no default to allow deprecated size prop to work via effectiveEnvironment computed } ) const slots = useSlots() /** * Emits deprecation warnings for deprecated props * * Watches for tooltip prop usage and logs warning only when prop is provided. * Warning is shown once when component mounts or when tooltip changes. */ watch(() => props.tooltip, (tooltip) => { if (tooltip) { console.warn( '[FzButton] The "tooltip" prop is deprecated and will be removed in a future version. ' + 'Please use the FzTooltip component to wrap your button instead.' ) } }, { immediate: true }) /** * Emits deprecation warnings for deprecated size prop * * Watches for size prop usage and logs warning with migration path to environment prop. */ watch(() => props.size, (size) => { if (size !== undefined) { const mappedEnvironment = sizeToEnvironmentMapping[size] // Check if both environment and size are provided and conflict if (props.environment && props.environment !== mappedEnvironment) { console.warn( `[FzButton] Both "size" and "environment" props are provided. ` + `"environment=${props.environment}" will be used and "size=${size}" will be ignored. ` + `Please remove the deprecated "size" prop.` ) } else { console.warn( `[FzButton] The "size" prop is deprecated and will be removed in a future version. ` + `Please use environment="${mappedEnvironment}" instead of size="${size}".` ) } } }, { immediate: true }) /** * Determines if the button is in an interactive state * * Returns true when the button is not disabled, allowing hover and focus * visual feedback. Used throughout the component to conditionally apply * interactive classes. */ const isInteractive = computed(() => !props.disabled) /** * Computes CSS classes based on the selected variant * * Returns dynamic classes for each variant, including background colors, text colors, * hover states, and focus states. Danger and success variants use semantic color tokens * (bg-semantic-error, bg-semantic-success) for consistent theming. Hover and focus classes * are conditionally applied based on the disabled state to prevent visual feedback on * non-interactive buttons. */ const customVariantClasses = computed(() => { switch (props.variant) { case 'secondary': return { 'bg-core-white': true, 'text-grey-500': true, '!border-grey-200': true, 'hover:bg-grey-100': isInteractive.value, 'hover:!border-grey-200': isInteractive.value, 'focus:bg-core-white': isInteractive.value, 'focus:!border-blue-600': isInteractive.value, 'disabled:bg-grey-50': true, 'disabled:text-grey-200': true, 'disabled:!border-grey-200': true, } case 'invisible': return { 'bg-transparent': true, 'text-grey-500': true, '!border-transparent': true, 'hover:bg-grey-100': isInteractive.value, 'hover:!border-grey-100': isInteractive.value, 'focus:bg-transparent': isInteractive.value, 'focus:!border-blue-600': isInteractive.value, 'disabled:bg-grey-50': true, 'disabled:text-grey-200': true, 'disabled:!border-grey-200': true, } case 'danger': return { 'bg-semantic-error-200': true, 'text-core-white': true, 'hover:bg-semantic-error-300': isInteractive.value, 'focus:bg-semantic-error-200': isInteractive.value, 'focus:!border-semantic-error-300': isInteractive.value, 'disabled:bg-semantic-error-100': true, } case 'success': return { 'bg-semantic-success-200': true, 'text-core-white': true, 'hover:bg-semantic-success-300': isInteractive.value, 'focus:bg-semantic-success-200': isInteractive.value, 'focus:!border-semantic-success-300': isInteractive.value, 'disabled:bg-semantic-success-100': true, } case 'primary': default: return { 'bg-blue-500': true, 'text-core-white': true, 'hover:bg-blue-600': isInteractive.value, 'focus:bg-blue-500': isInteractive.value, 'focus:!border-blue-600': isInteractive.value, 'disabled:bg-blue-200': true, } } }) /** * Determines the effective environment based on environment or size prop * * Priority: environment prop > size prop mapped to environment > default 'frontoffice'. * The size prop is deprecated and only used for backward compatibility. */ const effectiveEnvironment = computed((): ButtonEnvironment => { if (props.environment) { return props.environment } if (props.size) { return sizeToEnvironmentMapping[props.size] } return 'frontoffice' }) /** * Determines if both icon and label/slot content are present * * Icons are only rendered when accompanied by text content to ensure proper * spacing and layout. This prevents icon containers from rendering unnecessarily. */ const iconAndLabel = computed(() => Boolean((props.label || slots.default) && props.iconName)) const staticClasses = [ 'relative', 'rounded', 'flex', 'flex-shrink', 'items-center', 'justify-center', 'font-normal', '!text-[16px]', '!leading-[20px]', 'border-1', 'border-transparent', 'gap-8' ] const staticIconClasses = ['flex', 'items-center', 'justify-items-center'] /** * Computes dynamic size-based classes for the button * * Focus border classes are only applied when the button is not disabled. */ const classes = computed(() => { const env = effectiveEnvironment.value return { // Height classes (explicit for PurgeCSS detection) 'h-32': env === 'backoffice', 'h-44': env === 'frontoffice', // Padding classes (same for both environments) 'px-12': true, // Min-width classes (same for both environments) 'min-w-96': true, ...customVariantClasses.value } }) /** * Computes classes for the label/slot container * * By default, includes 'truncate' class to handle text overflow with ellipsis, * plus typography classes (font-normal, text-16, leading-20) for consistent text styling. * When overrideContainerClass is true, only the custom containerClass is applied, * allowing full control over container styling. Otherwise, custom classes are merged * with the default truncate behavior and typography. */ const containerClass = computed(() => { if (props.overrideContainerClass) { return props.containerClass } return ["truncate", "font-normal", "!text-[16px]", "!leading-[20px]", props.containerClass] }); </script> <template> <button type="button" :disabled="disabled" :aria-disabled="disabled ? 'true' : 'false'" :class="[staticClasses, classes]" > <div v-if="slots.before || (iconAndLabel && iconPosition === 'before')" :class="staticIconClasses"> <slot name="before"> <FzIcon v-if="iconName" :name="iconName" size="md" :variant="iconVariant" /> </slot> </div> <div v-if="label || slots.default" :class="containerClass"> <slot> {{ label }} </slot> </div> <div v-if="slots.after || (iconAndLabel && iconPosition === 'after')" :class="staticIconClasses"> <slot name="after"> <FzIcon v-if="iconName" :name="iconName" size="md" :variant="iconVariant" /> </slot> </div> </button> </template> |