@xsolla/xui-button 0.191.0 → 0.193.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -476,11 +476,13 @@ A button variant that displays only an icon. Requires `aria-label` for accessibi
476
476
 
477
477
  A flexible button with more granular control over background, hover fills, and styling.
478
478
 
479
+ Forwards a `ref` to the underlying `<button>` element, and inherits `ThemeOverrideProps` (`themeMode`, `themeProductContext`).
480
+
479
481
  **FlexButton Props:**
480
482
 
481
483
  | Prop | Type | Default | Description |
482
484
  | :-------------- | :------------------------------------------------------------------------------- | :--------- | :------------------------------------------------------------- |
483
- | children | `ReactNode` | - | The button label content. |
485
+ | children | `ReactNode` | - | The button label content. Optional — omit for an icon-only button, which renders no text slot so the icon stays centred in the hit area. |
484
486
  | variant | `"brand" \| "primary" \| "secondary" \| "tertiary" \| "brandExtra" \| "inverse"` | `"brand"` | The visual style variant. |
485
487
  | size | `"xl" \| "lg" \| "md" \| "sm" \| "xs"` | `"md"` | The size of the button. |
486
488
  | background | `boolean` | `false` | Whether to show background fill. |
@@ -492,6 +494,16 @@ A flexible button with more granular control over background, hover fills, and s
492
494
  | onPress | `() => void` | - | Callback fired when button is pressed. |
493
495
  | type | `"button" \| "submit" \| "reset"` | `"button"` | The HTML button type attribute. |
494
496
 
497
+ **`getFlexButtonBoxSize(size?)`**
498
+
499
+ Returns the square side, in px, of an icon-only `FlexButton` — `20 | 22 | 28 | 32 | 36` for `xs`–`xl`, defaulting to `md`. Use it when a layout has to reserve a matching column for a button it does not render itself (as `Modal`'s header does), instead of hardcoding the number. `noPadding` does not change it; only the inner padding is removed.
500
+
501
+ ```tsx
502
+ import { getFlexButtonBoxSize } from "@xsolla/xui-button";
503
+
504
+ <Box style={{ minWidth: getFlexButtonBoxSize("xl") }} />; // 36
505
+ ```
506
+
495
507
  ---
496
508
 
497
509
  ### ButtonGroup
@@ -169,8 +169,15 @@ interface IconButtonProps extends ThemeOverrideProps {
169
169
  */
170
170
  declare const IconButton: React.FC<IconButtonProps>;
171
171
 
172
- interface FlexButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "type"> {
173
- /** Button label. Omit for icon-only buttons (provide `aria-label`). */
172
+ interface FlexButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "type">, ThemeOverrideProps {
173
+ /**
174
+ * Button label. Omit for icon-only buttons (provide `aria-label`).
175
+ *
176
+ * An icon may also be passed directly as `children` instead of via
177
+ * `iconLeft`/`iconRight`. When `children` carries no text, the button is
178
+ * treated as icon-only and renders as a square sized from the design-system
179
+ * height token for `size`.
180
+ */
174
181
  children?: ReactNode;
175
182
  /** Visual variant of the button */
176
183
  variant?: "brand" | "primary" | "secondary" | "tertiary" | "brandExtra" | "inverse";
@@ -190,6 +197,9 @@ interface FlexButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElem
190
197
  * The component applies padding via an inline style, which overrides any CSS
191
198
  * class or `style` prop a consumer passes, so this prop is the supported way
192
199
  * to render a zero-padding FlexButton (e.g. an inline text action).
200
+ *
201
+ * Icon-only buttons keep their square dimensions when `noPadding` is set —
202
+ * only the inner padding is removed.
193
203
  * @default false
194
204
  */
195
205
  noPadding?: boolean;
@@ -219,11 +229,29 @@ interface FlexButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElem
219
229
  "aria-controls"?: string;
220
230
  testID?: string;
221
231
  }
232
+ /**
233
+ * Total hit-area size of an icon-only `FlexButton`, in px. `noPadding` does not
234
+ * change it — only the inner padding is removed.
235
+ */
236
+ declare const getFlexButtonBoxSize: (size?: NonNullable<FlexButtonProps["size"]>) => number;
222
237
  /**
223
238
  * FlexButton - A compact button component designed for use in modals and popups.
224
239
  *
225
240
  * Renders as a semantic `<button>` element with full ARIA support.
226
241
  *
242
+ * ## Icon-only buttons
243
+ *
244
+ * A FlexButton is icon-only when it has no text label and an icon is supplied
245
+ * either as `children` or via `iconLeft`/`iconRight`. Icon-only buttons render
246
+ * as a square whose side equals `theme.sizing.flexButton(size).height`, so they
247
+ * line up with the Modal header icon slots (36x36 at `size="xl"`).
248
+ *
249
+ * ```tsx
250
+ * <FlexButton variant="secondary" size="xl" aria-label="Go back">
251
+ * <BackwardAlt variant="line" />
252
+ * </FlexButton>
253
+ * ```
254
+ *
227
255
  * ## Accessibility Features
228
256
  *
229
257
  * - **Semantic HTML**: Renders as a native `<button>` element
@@ -232,7 +260,7 @@ interface FlexButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElem
232
260
  * - **Focus Indicator**: Visible focus ring for keyboard navigation
233
261
  * - **Screen Reader Support**: Announces button label, state, and any associated descriptions
234
262
  */
235
- declare const FlexButton: React.FC<FlexButtonProps>;
263
+ declare const FlexButton: React.ForwardRefExoticComponent<FlexButtonProps & React.RefAttributes<HTMLButtonElement>>;
236
264
 
237
265
  interface AppButtonProps extends ThemeOverrideProps {
238
266
  /** Size of the button */
@@ -341,4 +369,4 @@ interface ButtonGroupProps extends ThemeOverrideProps {
341
369
  */
342
370
  declare const ButtonGroup: React.FC<ButtonGroupProps>;
343
371
 
344
- export { AppButton, type AppButtonProps, Button, ButtonGroup, type ButtonGroupProps, type ButtonProps, FlexButton, type FlexButtonProps, IconButton, type IconButtonProps };
372
+ export { AppButton, type AppButtonProps, Button, ButtonGroup, type ButtonGroupProps, type ButtonProps, FlexButton, type FlexButtonProps, IconButton, type IconButtonProps, getFlexButtonBoxSize };
package/native/index.d.ts CHANGED
@@ -169,8 +169,15 @@ interface IconButtonProps extends ThemeOverrideProps {
169
169
  */
170
170
  declare const IconButton: React.FC<IconButtonProps>;
171
171
 
172
- interface FlexButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "type"> {
173
- /** Button label. Omit for icon-only buttons (provide `aria-label`). */
172
+ interface FlexButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "type">, ThemeOverrideProps {
173
+ /**
174
+ * Button label. Omit for icon-only buttons (provide `aria-label`).
175
+ *
176
+ * An icon may also be passed directly as `children` instead of via
177
+ * `iconLeft`/`iconRight`. When `children` carries no text, the button is
178
+ * treated as icon-only and renders as a square sized from the design-system
179
+ * height token for `size`.
180
+ */
174
181
  children?: ReactNode;
175
182
  /** Visual variant of the button */
176
183
  variant?: "brand" | "primary" | "secondary" | "tertiary" | "brandExtra" | "inverse";
@@ -190,6 +197,9 @@ interface FlexButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElem
190
197
  * The component applies padding via an inline style, which overrides any CSS
191
198
  * class or `style` prop a consumer passes, so this prop is the supported way
192
199
  * to render a zero-padding FlexButton (e.g. an inline text action).
200
+ *
201
+ * Icon-only buttons keep their square dimensions when `noPadding` is set —
202
+ * only the inner padding is removed.
193
203
  * @default false
194
204
  */
195
205
  noPadding?: boolean;
@@ -219,11 +229,29 @@ interface FlexButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElem
219
229
  "aria-controls"?: string;
220
230
  testID?: string;
221
231
  }
232
+ /**
233
+ * Total hit-area size of an icon-only `FlexButton`, in px. `noPadding` does not
234
+ * change it — only the inner padding is removed.
235
+ */
236
+ declare const getFlexButtonBoxSize: (size?: NonNullable<FlexButtonProps["size"]>) => number;
222
237
  /**
223
238
  * FlexButton - A compact button component designed for use in modals and popups.
224
239
  *
225
240
  * Renders as a semantic `<button>` element with full ARIA support.
226
241
  *
242
+ * ## Icon-only buttons
243
+ *
244
+ * A FlexButton is icon-only when it has no text label and an icon is supplied
245
+ * either as `children` or via `iconLeft`/`iconRight`. Icon-only buttons render
246
+ * as a square whose side equals `theme.sizing.flexButton(size).height`, so they
247
+ * line up with the Modal header icon slots (36x36 at `size="xl"`).
248
+ *
249
+ * ```tsx
250
+ * <FlexButton variant="secondary" size="xl" aria-label="Go back">
251
+ * <BackwardAlt variant="line" />
252
+ * </FlexButton>
253
+ * ```
254
+ *
227
255
  * ## Accessibility Features
228
256
  *
229
257
  * - **Semantic HTML**: Renders as a native `<button>` element
@@ -232,7 +260,7 @@ interface FlexButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElem
232
260
  * - **Focus Indicator**: Visible focus ring for keyboard navigation
233
261
  * - **Screen Reader Support**: Announces button label, state, and any associated descriptions
234
262
  */
235
- declare const FlexButton: React.FC<FlexButtonProps>;
263
+ declare const FlexButton: React.ForwardRefExoticComponent<FlexButtonProps & React.RefAttributes<HTMLButtonElement>>;
236
264
 
237
265
  interface AppButtonProps extends ThemeOverrideProps {
238
266
  /** Size of the button */
@@ -341,4 +369,4 @@ interface ButtonGroupProps extends ThemeOverrideProps {
341
369
  */
342
370
  declare const ButtonGroup: React.FC<ButtonGroupProps>;
343
371
 
344
- export { AppButton, type AppButtonProps, Button, ButtonGroup, type ButtonGroupProps, type ButtonProps, FlexButton, type FlexButtonProps, IconButton, type IconButtonProps };
372
+ export { AppButton, type AppButtonProps, Button, ButtonGroup, type ButtonGroupProps, type ButtonProps, FlexButton, type FlexButtonProps, IconButton, type IconButtonProps, getFlexButtonBoxSize };