# GamefaceUI: full documentation > Every page, as sections of at most ~1,600 characters separated by `---`. Each section starts > with a SOURCE tag naming its page URL and heading anchor; a section split into parts is headed `(i/n)`. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#520] ## Changelog: 5.2.0 Latest #### 🛠 Navigation Improvements Navigation now integrates the spatial navigation changes from [coherent-gameface-interaction-manager 3.1.0](https://frontend-tools.coherent-labs.com/interaction-manager/changelog/). - Feature Navigation.Area: Added the `onEdge` prop, called when navigation hits the edge of the area. Use it to move focus to another area - see Moving between areas. - Feature Navigation: Added `setEdgeHandler` for setting or removing an area’s edge handler after it has mounted. - Feature Navigation: `switchArea` accepts `{ direction, fallback }` options for focusing the element closest to where navigation enters the area. - Change Navigation: `focusFirst`, `focusLast` and `switchArea` now return the focused element, or `null`. When nothing is focused, the navigation `scope` is no longer updated. **Note:** Requires `coherent-gameface-interaction-manager` 3.1.0 or later. Run `gameface-cli update` to pick up the changes. `Navigation` gets a minor bump, and every component that depends on it gets a patch bump. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#512] ## Changelog: 5.1.2 - Fix Scroll: Clicking and holding on the scroll bar track no longer makes a small handle bounce endlessly around the cursor. The handle now stops under the cursor. - Fix Scroll: Releasing the mouse outside the scroll bar now stops the click-and-hold scrolling. - Fix Scroll: The scroll step for track clicks now shrinks back when the content gets shorter, instead of keeping the largest step it ever reached. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#511] ## Changelog: 5.1.1 - Fix Components with navigation actions (`onAction`) no longer leak memory. Their action handlers were never removed from the event bus on unmount, so each unmounted component and its DOM stayed in memory. - Fix Scroll: The `property-scroll` listener is now removed on unmount. - Feature EventBus: `once` now returns a function that removes the listener, so a `once` listener that hasn’t fired yet can be cleaned up with `onCleanup(eventBus.once(...))`. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#510] ## Changelog: 5.1.0 - New Added the Style TOM plugin and CSSTOM style runtime: a `style={{...}}` value driven by a signal (e.g. `` `${x()}px` ``) is now automatically rewritten at build time into the shape Gameface’s CSS Typed Object Model understands, so updating it at runtime skips the string parsing a plain `element.style` write would otherwise require on every change. `transform` strings (`translate()`, `scale()`, `rotate()`, `skewX()`, `skewY()`) get the same treatment. No changes needed to existing components - this only affects the small set of properties Gameface documents as CSSTOM-eligible; everything else keeps working exactly as before. - New Added an optional dev-server report listing the dynamic styles the Style TOM plugin couldn’t rewrite, with the reason and a suggested fix for each. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#500] ## Changelog: 5.0.0 #### ⚠️ Breaking Changes - Breaking Change `Icon` and `BackgroundImage` were removed. Use Image instead. See Migrating from Icon and BackgroundImage. - Breaking Change Adding an icon is now done via `Image.icons.*` (previously `Icon.*`). Dot paths now start at `src/assets` instead of `src/assets/icons`, so existing paths gain an `icons.` prefix. - Breaking Change `Image` renders a `div` background, so there is no load-error fallback. The default size is also `3.5rem` square unless you set dimensions. - Breaking Change MaskImage no longer accepts the undocumented `onAction`, `anchor`, and `refObject` props. #### Texture atlases - New `Image.folder.name` can now be packed into texture atlases at build time. - New The plugin groups images by view, builds sheet PNGs, and resolves them automatically at runtime. - New Atlas behavior is configured in `vite.config.mts` and reported in the build output. See Images and texture atlases. #### Component changes - Feature Image: Added `options` for `size`, `position`, and `repeat`, plus child support. - Feature Image: Dot paths are type-checked and autocomplete is generated from `src/assets`. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#420] ## Changelog: 4.2.0 - New Added the Chart component family for HUD data visualisation: Pie, Donut, Bar, Line, Area and Spider. All of them share one data model, palette, animation system and set of slots. - Feature Added the shared Chart slots - `Chart.Legend`, `Chart.Tooltip`, `Chart.Labels`, `Chart.XAxis`, `Chart.YAxis` and `Chart.Grid`. All are opt-in. - Feature Charts tween between data sets when given an `animation` prop. Without one, a chart does no per-frame work. - Feature Hover, tooltip and click are opt-in through the `interactive` prop, using native SVG hit-testing or a single overlay that resolves the hovered point mathematically. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#410] ## Changelog: 4.1.0 - New Added Trackers component for rendering many per-entity UI markers - nameplates, minimap blips, damage numbers - that update position every frame without going through Solid’s reactivity. Each tracked entity gets one DOM node, built once; later updates just move, hide, or show it. - Feature Added Trackers.Item slot for defining an individual tracked entity inside a `Trackers` container. - Feature Added `updateTrackers` method for moving, hiding, or showing tracked items directly from JavaScript - pass a single update or a batch of them in one call. - Feature Trackers.Item: added `scale` and `rotate` props, composed into the same transform `Trackers` already uses for positioning. - Feature Tracked items can also be moved directly from the engine, by triggering a `trackers:` event - see Move item from the engine. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#400] ## Changelog: 4.0.0 (1/2) #### ⚠️ Breaking Changes - Breaking Change A view is now just a folder holding a component named after it - `src/views/hud/Hud.tsx`. The `index.html`, `index.tsx` and `index.css` files each view used to carry are gone; the HTML document and the code that renders the component into it are generated in development and in the production build alike. See Creating a View. To migrate an existing view, delete its `index.html` and `index.tsx`, and rename `index.css` to `global.scss` (or `global.css`). Make sure the component file is named after its folder - `menu/Menu.tsx`, `chart-playground/ChartPlayground.tsx`; case and separators are ignored, but a folder with no matching component is no longer served or built. - Breaking Change Global styles shared by every view now live in `src/views/global.scss`, which is applied before each view’s own `global.scss` and before its module styles. The boilerplate uses it for the root font size and to make the body fill the viewport, so those rules no longer need repeating per view. See Styling a View. #### Development server - New Opening `http://localhost:3000` now lists every view in `src/views` with a link to it, instead of showing nothing. The page renders in the browser and inside `Player.exe`, so you can point the player at the root URL and switch views without restarting it. - Feature The trailing slash is no longer required when opening a view. `http://localhost:3000/hud` works the same as `http://localhost:3000/hud/`, in development and in `vite preview`. #### Component fixes --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#400] ## Changelog: 4.0.0 (2/2) - Fix Icon: The `fill` prop had no effect - the class it applies was missing from the component’s stylesheet, so an icon marked `fill` kept rendering at the default size instead of filling its container. - Fix Icon: The default size no longer squashes icons into a square. `height` is `auto` instead of a fixed `2.5rem`, so a non-square icon keeps its aspect ratio at the default `2.5rem` width. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#330] ## Changelog: 3.3.0 - New Added the `@recipes` path alias, so a recipe can be imported as `@recipes/SegmentedProgressBar/SegmentedProgressBar` instead of a relative path. Browse the available recipes in Community Recipes. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#321] ## Changelog: 3.2.1 - Fix Icon: Icon and folder names are no longer restricted to valid JavaScript identifiers. Separators such as `-`, `_` and spaces are now converted to camelCase, so `hud icons/round-star.svg` becomes ``. Names that cannot produce a usable key - ones with no letters or digits at all, or ones starting with a digit - now fail the icon generation with a descriptive error instead of emitting invalid TypeScript. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#320] ## Changelog: 3.2.0 - New Components are now versioned individually, independent of the library version. A fix to `Slider` bumps `Slider` and nothing else, so you can pick up an improvement to one component without pulling in unrelated changes across your UI. See Updating components for how to update everything at once, or one component at a time. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#310] ## Changelog: 3.1.0 - Feature Dropdown: Exposed `toggle` method in the `ref` to programmatically open/close the dropdown. - Feature Dropdown: Added a `multiple` prop that allows selecting several options at once. When enabled, the dropdown stays open while selecting, clicking a selected option deselects it, and `onChange` returns an array of the selected values. The exposed `ref` gains a `selectedValues` accessor and a `deselectOption` method. - Feature Slider: Added an `onChangeEnd` prop that fires once the user finishes interacting with the slider (e.g. on mouse release), useful for committing the final value. - New Added TwoHandleSlider component for selecting a numeric range with a lower (start) and an upper (end) handle. - Feature Added `Track`, `Fill`, `Thumb`, `Handle` and `Grid` slots for the TwoHandleSlider component. - Feature Slider & TextSlider: The `value` prop is now reactive - updating it externally moves the slider (two-way binding). - Feature Dropdown: Added a `value` prop that controls and sets the selection. It is reactive - updating it externally changes the selection (two-way binding) - accepts an array in `multiple` mode, and takes precedence over the `selected` prop on `Dropdown.Option`. - Feature Slider: Exposed a `stepValue` method in the `ref` to step the value up or down by the `step` amount programmatically. - Feature Dropdown: The dropdown trigger now spans the full width (`100%`) of the dropdown component, making it easier to restyle. - Feature Slider & TextSlider: `onChange` now only fires when the value actually changes instead of on every mouse move. - Feature Icon: Improved rendering performance by swapping directly to the fallback image on error instead of rendering a separate fallback component. - Feature TextInput, PasswordInput & NumberInput: Added a `delay` prop that debounces the `onChange` callback by the given amount in milliseconds. - Fix NumberInput: The `value` prop is now reactive — updating it is reflected in the input (two-way binding), matching the other input components. - Fix ToggleButton: Make the `` scale off the size of the `` element instead of the indicator’s size. This ensures that the indicator scales correctly when the button size changes. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#301] ## Changelog: 3.0.1 #### 🛠 Navigation Improvements - Fix Navigation: `callback` in the `ActionCfg` type is now optional. Overriding a default action with only key/button bindings no longer requires passing an empty callback or a redundant `global` flag. - Feature Navigation: `addAction` now warns at runtime when the provided config has no `callback` and no `global: true`, or no `key`/`button` binding, as such an action would be unreachable or produce no effect. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#300] ## Changelog: 3.0.0 (1/2) #### ⚠️ Breaking Changes - Breaking Change Removed default `width` and `height` styles from Relative component to avoid unexpected behavior. Now, the `Relative` component will only take up as much space as its content requires unless dimensions are explicitly set through styles or classes. - Breaking Change Removed the `
` wrapper from the Tab component to avoid unexpected layout behavior. Now, the `Tab` component will render its content directly without an additional wrapper element. This change may affect styling and layout, so please review your usage of the `Tab` component and adjust styles accordingly. #### ✨ New View UI - New Added a new sample `Inventory UI` prototype view at `src/views/inventory`. It can be accessed by navigating to `/inventory` in the development server. - New Added new assets related to the `Inventory UI` (icons & font). **Asset Credits:** The “Cinzel” font is provided by Google Fonts under the SIL Open Font License. The UI icons are provided by [game-icons.net](https://game-icons.net) under the CC BY 3.0 license. #### 🛠 Component Enhancements - Feature Added `center` prop to the Absolute component for easily centering content. - Feature Added dot-notation access for Column sizes. This allows you to use specific `Column` sizes without needing to import each one separately. For example, you can now write `` instead of ``. **Caution:** The previous method of importing individual size components is still supported for backward compatibility. You can continue using ``, ``, etc., as before. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#300] ## Changelog: 3.0.0 (2/2) - Feature Added `fill` prop to the Icon & Image components allowing them to fill the space of their parent containers. - Fix Icon: Fixed typescript types suggestion for the component’s props. - Feature Added `width` and `height` props to the Block component for easier size customization when prototyping. - Feature Added dot-notation access for the Top, Content, and Bottom components within the Layout component. You can now write ``, ``, and `` without needing to import them separately. **Caution:** The previous method of importing these components individually is still supported for backward compatibility. You can continue using ``, ``, and `` as before. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#210] ## Changelog: 2.1.0 - Feature Added `Grid.Tile` slot for the Grid. This allows you to use the `GridTile` component without importing it separately. You can now write `` instead of ``. **Caution:** The previous method of importing `GridTile` separately is still supported for backward compatibility. You can continue using `` as before if you prefer. - Feature Added `gap`, `row-gap`, and `column-gap` props to the Flex & Grid components. **Caution:** These properties are supported in Gameface 2.2 and later versions. - Feature Added `row-class`, `column-class`, `row-style`, and `column-style` props to the Grid component for customizing the styles of internal row and column wrappers. - Fix Dropdown: Fixed content inside `Dropdown.Trigger` not being vertically centered. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#200] ## Changelog: 2.0.0 (1/2) #### ⚠️ Breaking Changes - Breaking Change The `ref` prop on layout components (Absolute, Flex, Block, etc.) that don’t have any other methods or properties now exposes the DOM node directly. You no longer need to access the `.element` property.\ Affected components: Absolute, Block, Bottom, Column, Content, Flex, Grid, GridTile, Layout, Layout3D, List, Relative, Row, TabLink, Tab, Top, Transform, BackgroundImage, MaskImage. #### ✨ New Features - New **Navigation** - Introduced a new utility component for handling spatial navigation, gamepad/keyboard interactions and focus management. - Feature **Added Navigation.Area slot** for grouping navigable components within the Navigation component. - Feature **Custom Component Action Subscriptions:** Custom components can now subscribe to Navigation actions. #### 🛠 Component Enhancements ##### Navigation Support The following components have been extended to support onAction and anchor props. They now respond to specific spatial navigation actions when placed inside a Navigation area: Component | Props | Supported Actions Button, RoundedButton | onAction anchor | — Checkbox, Accordion | Props | select Dropdown | Props | select back NumberInput | Props | select back move-up/down PasswordInput, TextInput | Props | select back Radio, Segment, Stepper, Slider, TextSlider | Props | move-left/right XYSlider, Scroll | Props | pan Tooltip | Props | back TextBlock, InlineTextBlock, Modal | onAction anchor | — Keybind | Props | select ColorPicker, RadialMenu, Carousel, Tutorial | onAction anchor | — --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#200] ## Changelog: 2.0.0 (2/2) ##### Component improvements and fixes - New Toast: Added `dismiss` argument to the body function for programmatically closing a toast. - New Tutorial: Added `onStart` and `onEnd` props for adding a logic when the tutorial starts or ends. - New Modal: Forbid any mouse events outside the modal when there is a `Modal.Overlay`. - Fix Checkbox: Fixed an issue where the `onChange` handler was called on component mount. - Fix ToggleButton: Fixed `checked` prop not reacting to signal state changes. - Fix Slider & XYSlider: Fixed drag event not cleaning up if component unmounts during dragging. #### 📖 New Guides - New List - Provide a guide on how to initialize list items as navigable elements within a Navigation area. - New GridTile - Provide a guide on how to initialize grid tiles as navigable elements within a Navigation area. - New Keybinds - Provide an extended overview on gamepad support. - New ColorPicker - Provide a step by step guide on how to enable navigation support for the component. - New RadialMenu - Provide a step by step guide on how to enable navigation support for the component. - New Carousel - Provide a step by step guide on different ways to enable navigation for the component. - New Tutorial - Provide a step by step guide on different ways to enable navigation for the component. - New Toast - Provide a guide on how to close a toast programmatically. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#120] ## Changelog: 1.2.0 New Added Icon component. New Added gamepad button images to the `src/assets/icons/` folder. The icons can be used with the new Icon component. Feature Added an automatic script that runs with the development server for updating the Icon component’s type whenever new images are added to the `src/assets/icons` directory. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#110] ## Changelog: 1.1.0 New Added Tutorial component. Feature Added `Tutorial.Step` slot for the Tutorial component. New Added an optional tutorial to the Menu UI at `src/views/menu` --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#1012] ## Changelog: 1.0.12 New Added RadialMenu component. Feature Added `RadialMenu.Item` slot for the RadialMenu component. Feature Added `RadialMenu.Selector` slot for customizing the colored wedge and active slice of the RadialMenu. Feature Added `RadialMenu.Content` slot for displaying static elements inside the center of the RadialMenu. Feature Added `RadialMenu.Indicator` slot for rendering the rotating highlight arc that follows the currently selected item in the RadialMenu. Feature Added `RadialMenu.Icon` slot for displaying a customizable pointer icon inside the indicator of the RadialMenu. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#1011] ## Changelog: 1.0.11 New Added Progress.Bar component. Feature Added `Progress.Bar.Fill` slot for the Progress.Bar component. New Added Progress.Circle component. Feature Added `Progress.Circle.Fill`, `Progress.Circle.Outline`, and `Progress.Circle.Text` slots for the Progress.Circle component. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#1010] ## Changelog: 1.0.10 New Added a guide on how to work with the state of a component. Feature Added an option for the Image, LiveView, BackgroundImage, and MaskImage to fill its container. The option can be enabled through the `fill` prop. Feature Top, Content and Bottom: added `basis` prop to set the `flex-basis` as a percentage. Allowing for quick layout customization. Feature The size of the ColorPicker can now be changed through its `size` prop. Available sizes are: `S`, `M`, `L`, and `XL`. Fix Dropdown: fixed dropdown trigger displaying the value of an option and not the content related to it. Fix Dropdown: fixed dropdown options causing overflow when not visible. Change Dropdown: make dropdown options invert their position when not enough space. Exposed `inverted-class` prop to customize the inverted state. Fix Dropdown: fixed `onChange` not triggering when the changed option’s value is `""`. Feature Scroll: Expose the inner html element of the scroll’s content with a `ref`. #### 1.0.9 New Added Keybinds component. New Added Keybind component. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#108] ## Changelog: 1.0.8 New Added Tooltip component for displaying informative tooltips. New Added Toast component for displaying popups. Change **Modal: The component has been moved from `src/components/Basic/Modal` to `src/components/Feedback/Modal` folder!** --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#107] ## Changelog: 1.0.7 New Revamped the default Menu UI at `src/views/menu`. Feature Modal: added `onOpen` and `onClose` props. Feature Tabs: `onBeforeTabChange` can now return `false` to cancel the switch. The handler now receives **both** the current and next tab. Feature Segment: added `class-selected` prop for customizing its selected state. Change Button: adjusted size scale (S/M/L are slightly smaller). Fix Slider: fixed rounding issues with fractional values. Fix Layout / Top, Content, Bottom: components now stretch to the container and fill remaining space. (Also applies to Content and Bottom.) Fix Input components: dimensions are now easily customizable. Fix Prevented `onChange` from firing on mount for Segment, Dropdown, ToggleButton, and XYSlider. Fix Scroll: prevented `onScroll` from firing on mount. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#106] ## Changelog: 1.0.6 New Added Carousel component. Feature Added `Carousel.Items`, `Carousel.Pagination`, `Carousel.Next`, `Carousel.Prev` components for the Carousel component. Feature Added `Carousel.Item` slot for the Carousel.Items component. #### 1.0.5 New Added List component. Feature Added `Item` slot for the List component. Feature Added `Icon` slots for the List.Icon component. #### 1.0.4 New Added Modal component. Feature Added `Overlay` and `Window` slots for the Modal component. #### 1.0.3 New Added Pagination component. Feature Added `Control`, and `Item` slots for the Pagination component. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#102] ## Changelog: 1.0.2 New Added TextInput component. New Added PasswordInput component. New Added NumberInput component. Feature Added `Before`, `After`, `Input` and `Placeholder` slots for the TextInput component. Feature Added `Before`, `After`, `Input` and `VisibilityButton` slots for the PasswordInput component. Feature Added `IncreaseControl`, `DecreaseControl`, `Input` and `Placeholder` slots for the NumberInput component. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#101] ## Changelog: 1.0.1 New Added ColorPicker component for advanced color selection and manipulation. New Added Accordion component. Feature Added `Panel`, `Heading`, `Icon` and `Body` slots for the Accordion component. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#100] ## Changelog: 1.0.0 (1/2) New Added support for slots in components, allowing for more flexible and reusable component structures. New Added Checkbox component. New Added Radio component. New Added ToggleButton component. New Added Dropdown component. New Added Stepper component. New Added Segment component. New Added Slider component. New Added TextSlider component. New Added XYSlider component. Feature Added `Indicator` slot for the Segment component. Feature Added Segment.Button slot for the `Segment` component to create segment options. Feature Added `Track`, `Fill`, `Thumb`, `Handle` and `Grid` slots for the Slider component. Feature Added `Track`, `Fill`, `Thumb`, `Handle` and `Grid` slots for the TextSlider component. Feature Added `Background` and `Handle` slots for the XYSlider component. Feature Added `Content`, `Bar` and `Handle` slots for the Scroll component. Feature Added `Label`, `Control` and `Indicator` slots for the Checkbox component for easier customization. Feature Added Radio.Button slot for the `Radio` component to create radio options. Feature Added `Radio.ButtonLabel`, `Radio.ButtonControl` and `Radio.ButtonIndicator` for the Radio.Button slot to customize the radio button’s appearance and behavior. Feature Added `LabelLeft`, `LabelRight`, `Handle`, `Control` and `Indicator` slots for the ToggleButton component for easier customization. Feature Introduced `Dropdown.Trigger`, `Dropdown.Placeholder`, `Dropdown.Icon`, `Dropdown.Track`, and `Dropdown.Handle` slots for the Dropdown component, enabling enhanced customization of its appearance and behavior. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#100] ## Changelog: 1.0.0 (2/2) Feature Added the Dropdown.Options slot to the `Dropdown` component for creating dropdown options. Feature Introduced `Dropdown.Option` within the Dropdown.Options slot to allow customization of individual dropdown options. Feature Added the `Stepper.Control` slot to the Stepper component, allowing for greater customization of its design and functionality. Feature Introduced the Stepper.Items slot to the `Stepper` component for defining stepper items. Feature Introduced the `Stepper.Item` slot within Stepper.Items to allow the definition and customization of individual stepper items. Feature Added a custom ESLint plugin to the main Gameface UI repository to alert developers when component slots are misused or do not adhere to the defined specifications. Feature Added an option to use `attr:` for adding attributes to GamefaceUI components. Fix Fixed reactivity in `componentStyles`. Fix Fixed `Transform` component reactivity. Fix Resolved an issue where clicking on the track did not move the scroll handle properly in the Scroll component. Fix Resolved an issue where the scroll handle did not resize correctly when the scroll content’s size changed in the Scroll component. --- [SOURCE: https://gameface-ui.coherent-labs.com/changelog/#001-beta] ## Changelog: 0.0.1-beta New GamefaceUI’s initial release. New Core components for building intuitive game user interfaces. New Seamless integration with the SolidJS framework for reactive and efficient UI development. New Detailed documentation to help you get started quickly. Feature Support for using SVGs as SolidJS components. Feature Introduced a Vite plugin to optimize and transform UI source code for Gameface. Feature Added a Vite plugin to convert `style` properties to `class`, enhancing performance by reducing inline styles and leveraging CSS for better caching and reusability. Feature Simplified importing of UI assets with a new mechanism. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/] ## Gameface UI components A comprehensive collection of hight-performance, game-ready UI components optimized for Coherent Gameface. 🔎 Find component ### Basic ### Feedback ### Complex ### Layout ### Media ### Utility ### Performance No items found. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/] ## Accordion Menu The `Accordion` component is a vertically stacked set of interactive headings that each reveal an associated section of content. It allows users to expand and collapse sections to show or hide their content. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#installation] ## Accordion Menu: Installation Every component ships with the boilerplate. If you are working in your own project, add `Accordion` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Accordion ``` The CLI pulls in whatever `Accordion` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#usage] ## Accordion Menu: Usage To include an accordion in your UI, wrap one or more `Accordion.Panel` components within the `Accordion` component. Each panel contains an `Accordion.Heading` and an `Accordion.Body`: **index.tsx:** ```tsx import Accordion from '@components/Basic/Accordion/Accordion'; Heading 1 Accordion content Heading 2 Accordion content ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#api] ## Accordion Menu: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the Accordion’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the Accordion. `ref` | `AccordionRef \| undefined` | `undefined` | Reference to the Accordion instance, providing access to its methods for programmatic control. `multiple` | `boolean` | `false` | If `true`, allows multiple panels to be expanded at the same time. `disabled` | `boolean` | `false` | Disables the Accordion when set to `true`. `class-disabled` | `string` | `""` | Additional CSS classes to apply when the Accordion is disabled. `onChange` | `(title: string) => void` | `undefined` | Callback triggered whenever the expanded panels change. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#ref-api] ## Accordion Menu: Ref API To interact with the `Accordion` programmatically, you can use the `AccordionRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the Accordion’s root HTML element, useful for DOM access or styling. #### Methods Method | Parameters | Return Value | Description `expand` | `title: string` | `void` | Expands the panel with the given title. `collapse` | `title: string` | `void` | Collapses the panel with the given title. `expandAll` | none | `void` | Expands all panels. Only works if the Accordion has the `multiple` prop enabled. `collapseAll` | none | `void` | Collapses all panels. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#slots] ## Accordion Menu: Slots (1/4) #### Accordion.Panel The `Accordion.Panel` slot represents an individual section within the Accordion and must be included to render a panel on the `Accordion`. It contains a heading (rendered with `Accordion.Heading`) and a body (with `Accordion.Body`). ##### Properties Prop Name | Type | Default | Description `expanded` | `boolean` | `false` | If `true`, the panel is expanded by default. `title` | `string` | `""` | The title or label for the panel. It is used for programmatic manipulation. `disabled` | `boolean` | `false` | Disables the panel, preventing user interaction. `class-disabled` | `string` | `""` | Additional CSS classes applied when the panel is disabled. `class-expanded` | `string` | `""` | Additional CSS classes applied when the panel is expanded. `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply to the panel container. `class` | `string` | `""` | Additional CSS classes for the panel container. ##### Usage Creating an accordion menu with an expanded panel by default. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#slots] ## Accordion Menu: Slots (2/4) ```tsx import Accordion from '@components/Basic/Accordion/Accordion'; const App = () => { return ( Heading 1 Accordion content Heading 2 Accordion content ); }; export default App; ``` **Caution:** If no `title` prop is provided to `Accordion.Panel`, a unique identifier will be generated automatically. If you plan to programmatically manipulate the panel, it is recommended to specify a `title`. #### Accordion.Heading The `Accordion.Heading` slot is used inside an `Accordion.Panel` to define the clickable heading for that panel. It displays the panel’s title or label and handles user interaction for expanding or collapsing the panel. ##### Properties --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#slots] ## Accordion Menu: Slots (3/4) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply to the heading element. `class` | `string` | `""` | Additional CSS classes for the heading element. `children` | `JSX.Element` | `""` | Content of the heading, used to render text, HTML, or JSX elements within the heading. `onAction` | `Record void>` | `undefined` | Extends or overrides the heading’s default navigation action handlers. See Implemented Navigation Actions for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the heading’s actions will execute. Can be a CSS selector or HTMLElement. #### Accordion.Icon The `Accordion.Icon` slot allows you to customize or change the icon displayed inside the accordion’s heading. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply to the heading element. `class` | `string` | `""` | Additional CSS classes for the heading element. `children` | `JSX.Element` | `""` | Custom content, such as text, HTML, or JSX, to render as the accordion icon. **Note:** By default the icon will rotate by 180 degrees when the panel is expanded. You can customize this behavior by providing a custom class or styles to the icon slot. ##### Usage To use a custom icon, provide your desired content as children of the Accordion.Icon slot: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#slots] ## Accordion Menu: Slots (4/4) ```tsx import Accordion from '@components/Basic/Accordion/Accordion'; import CustomIcon from '@assets/CustomIcon'; const App = () => { return ( Heading 1 Accordion content Heading 2 Accordion content ); }; export default App; ``` #### Accordion.Body The `Accordion.Body` slot is used inside an `Accordion.Panel` to define the content area that is shown or hidden when the panel is expanded or collapsed. It displays the main content associated with the panel. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply to the body element. `class` | `string` | `""` | Additional CSS classes for the body element. `children` | `JSX.Element` | `""` | Content of the body, used to render text, HTML, or JSX elements within the body. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#implemented-navigation-actions] ## Accordion Menu: Implemented Navigation Actions The `Accordion.Heading` component slot implements the following navigation action by default: Action Name | Behavior `select` | Toggles the accordion panel (expands if collapsed, collapses if expanded) You can extend the `Accordion.Heading` with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import Accordion from '@components/Basic/Accordion/Accordion'; console.log('Custom select behavior!'), 'info': () => console.log('Show panel info') }} > Heading 1 Accordion content ``` For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#guide] ## Accordion Menu: Guide (1/6) #### Retrieve the modified panel’s title on change To detect which panel was last expanded or collapsed: - Use the `onChange` prop to handle changes in the Accordion’s panels. ##### Steps 1. Pass a callback function to the `onChange` prop. 2. The callback receives the `title` of the panel that was most recently expanded or collapsed. ```tsx import Accordion from '@components/Basic/Accordion/Accordion'; const App = () => { const handleChange = (title: string) => { console.log(title); }; return ( Heading 1 Accordion content Heading 2 Accordion content ); }; export default App; ``` #### Programmatically toggle a panel The `Accordion` component allows you to programmatically toggle a panel by providing its title as the argument. ##### Steps 1. Create a `ref` variable of type `accordionRef` and assign it to the `Accordion` component. 2. Use the `ref.expand(title)` method to programmatically expand the panel, such as in response to a button click or keyboard event. 3. Use the `ref.collapse(title)` method to programmatically collapse the panel, such as in response to a button click or keyboard event. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#guide] ## Accordion Menu: Guide (2/6) ```tsx import Accordion, {accordionRef} from '@components/Basic/Accordion/Accordion'; const App = () => { let accordion!: accordionRef; const handleKeyPress = (e: KeyboardEvent) => { if (e.keyCode === 13) { accordion.expand('heading-1'); } else if (e.keyCode === 27) { accordion.collapse('heading-1'); } }; return ( Heading 1 Accordion content Heading 2 Accordion content ); }; export default App; ``` #### Making accordion headings navigable The `Accordion.Heading` needs to be focused in order to respond to the `select` action. To enable gamepad/keyboard navigation for accordion headings, add them to a navigation area by assigning a CSS class and registering them with `Navigation.Area` or `navigationRef.registerArea()`. ##### Steps 1. Wrap your `Accordion` inside a `Navigation` component 2. Assign a CSS class to each `Accordion.Heading` you want to be navigable 3. Register the headings as a navigation area using either: - `navigationRef.registerArea()` with the class selector - Or wrap the accordion in `Navigation.Area` with the appropriate selector --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#guide] ## Accordion Menu: Guide (3/6) ```tsx import Navigation, { NavigationRef } from '@components/Utility/Navigation/Navigation'; import Accordion from '@components/Basic/Accordion/Accordion'; const App = () => { let navigationRef: NavigationRef | undefined; // Register accordion headings as a navigation area onMount(() => { navigationRef?.registerArea('accordion-headers', ['.accordion-heading']); }); return ( Settings Settings content Audio Audio content ); }; export default App; ``` #### Navigating accordion body content For more complex accordion implementations where the body contains navigable elements (like form inputs, buttons, or lists), you can create a `Navigation.Area` inside the `Accordion.Body` and automatically focus it when the panel expands. ##### Steps --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#guide] ## Accordion Menu: Guide (4/6) 1. Wrap the elements you wish to be navigable inside `Accordion.Body` with `Navigation.Area` 2. Use the `onChange` callback to detect when the panel expands 3. Call `navigationRef.focusFirst()` or `navigationRef.switchArea()` to focus the body’s navigation area 4. Optionally set up a `back` action to return focus to the accordion headings --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#guide] ## Accordion Menu: Guide (5/6) ```tsx import Navigation, { NavigationRef } from '@components/Utility/Navigation/Navigation'; import Accordion from '@components/Basic/Accordion/Accordion'; const App = () => { let navigationRef: NavigationRef | undefined; // Handle accordion panel changes const handleAccordionChange = (title: string) => { if (title === 'settings-panel') { // Focus the navigation area inside the expanded panel navigationRef?.focusFirst('settings-area'); } }; onMount(() => { // Register accordion headings as an area and focus it. navigationRef?.registerArea('accordion-headers', ['.accordion-heading'], true); // Configure back action to return to accordion headers navigationRef?.updateAction('back', { key: { binds: ['ESC'], type: ['press'] }, button: { binds: ['face-button-right'] }, callback: (scope) => { if (scope === 'settings-area') { navigationRef?.focusFirst('accordion-headers'); } } }); }); return ( Settings Audio Audio settings content ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/accordion/#guide] ## Accordion Menu: Guide (6/6) CSS for `.menu-item`: ```css .menu-item { padding: 1vmax; border-bottom: 1px solid #232323; background-color: #cecece; } .menu-item:focus { background-color: #b1b1b1; } ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/button/] ## Button The `Button` component is used to create button elements in the UI. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/button/#installation] ## Button: Installation Every component ships with the boilerplate. If you are working in your own project, add `Button` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Button ``` The CLI pulls in whatever `Button` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/button/#usage] ## Button: Usage The `Button` component provides various configuration options to create different types of buttons. For example, you can create disabled buttons, larger or smaller buttons, rounded buttons, and more. **index.tsx:** ```tsx import Button from '@components/Basic/Button/Button'; <> ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/button/#api] ## Button: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLButtonElement \| undefined` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. The HTML element can be accessed directly by the ref object. `disabled` | `boolean` | `false` | Specify if the button is disabled `size` | `'large' \| 'middle' \| 'small'` | `''` | Specify the size of the button. If an empty string is passed, the button won’t have any size. In that case, please specify the size through the `class` or `style` properties. `textFit` | `boolean` | `true` | Specify if the text inside the button should be fitted. By default, this option is **enabled**. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the button. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the button’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/button/#guide] ## Button: Guide #### Custom size To customize the size of the button, you can omit the `size` property and set the desired size using the `style` property or by applying a CSS class to the button. ```tsx import Button from '@components/Basic/Button/Button'; const App = () => { return ( ); }; export default App; ``` #### Disabling the button It is enough to set `disabled` attribute to the button. ```tsx import Button from '@components/Basic/Button/Button'; const App = () => { return ( ); }; export default App; ``` #### Custom font-size To customize the `font-size` of the text inside the button, set the `textFit` property to `false` (it is enabled by default). Then, you can specify the `font-size` using the `style` property or by applying a `class` to the button. ```tsx import Button from '@components/Basic/Button/Button'; const App = () => { return ( ); }; export default App; ``` #### Accessing the HTML element To access the `HTML` element of the component and make other modifications, you can add a `ref` property to the button. ```tsx import Button from '@components/Basic/Button/Button'; const App = () => { let ref: HTMLButtonElement; return ( ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/checkbox/] ## Checkbox The `Checkbox` component is used to create a checkbox element in the UI. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/checkbox/#installation] ## Checkbox: Installation Every component ships with the boilerplate. If you are working in your own project, add `Checkbox` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Checkbox ``` The CLI pulls in whatever `Checkbox` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/checkbox/#usage] ## Checkbox: Usage The `Checkbox` component allows the user to select or deselect a value. **index.tsx:** ```tsx import Checkbox from '@components/Basic/Checkbox/Checkbox'; <> V-Sync Fullscreen Mode Motion Blur Anti-Aliasing ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/checkbox/#api] ## Checkbox: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `CheckboxRef \| undefined` | `undefined` | A reference to the component that gives you access to its methods and the underlying HTML element. Useful if you need to set the value of the checkbox programmatically. `disabled` | `boolean` | `false` | Specify if the checkbox is disabled `value` | `any` | `''` | The value associated with the checkbox component. `checked` | `boolean` | `false` | Specify if the checkbox is checked initially. `onChange` | `(checked: boolean) => void` | `undefined` | A function that is called every time the checkbox is toggled. It can be used to retrieve whether the checkbox is checked. `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the checkbox’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/checkbox/#ref-api] ## Checkbox: Ref API To interact with the `Checkbox` programmatically, you can use the `CheckboxRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `checked` | `Accessor` | Read the current checked state: `ref.checked()` returns `true/false`. `value` | `any` | The value associated with the checkbox. `element` | `HTMLDivElement` | A reference to the checkbox’s root HTML element, useful for DOM access or styling. #### Methods Method | Parameters | Return Value | Description `setChecked` | `Setter` | `void` | Programmatically sets the checked state of the checkbox. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/checkbox/#slots] ## Checkbox: Slots (1/3) #### Checkbox.Label Allows customization of the checkbox’s label. This slot can be used to include additional elements in the label or place the label before the control of the checkbox. ##### Properties Prop Name | Type | Default | Description `before` | `boolean` | `false` | Specify if the label should be put before the checkbox control `children` | `JSX.Element` | `undefined` | Content to render inside the label, which can be any valid JSX element. ##### Usage ```tsx import Checkbox from '@components/Basic/Checkbox/Checkbox'; import Block from '@components/Layout/Block/Block'; const App = () => { return ( <> V-Sync Fullscreen Mode Motion Blur Anti-aliasing ); }; export default App; ``` **Caution:** If the `Label` slot is used then the other `children` of the `Checkbox` component won’t be rendered. #### Checkbox.Control This slot allows you to customize the control of the `Checkbox` component when it is unchecked. Use it to apply custom styles, classes or include additional elements in the control of the checkbox. ##### Properties --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/checkbox/#slots] ## Checkbox: Slots (2/3) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the checkbox control. `class` | `string` | `""` | Additional CSS classes to style the checkbox control. `children` | `JSX.Element` | `undefined` | Content to render inside the checkbox control, which can be any valid JSX element. ##### Usage ```tsx import Checkbox from '@components/Basic/Checkbox/Checkbox'; const App = () => { return ( <> V-Sync Fullscreen Mode Motion Blur Anti-aliasing ); }; export default App; ``` #### Checkbox.Indicator This slot allows you to override the default indicator displayed when the checkbox is checked. Use it to apply custom styles, classes or include additional elements in the indicator of the checkbox. **Note:** The `Checkbox.Indicator` slot is only rendered when used inside the `Checkbox.Control` slot. ##### Properties --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/checkbox/#slots] ## Checkbox: Slots (3/3) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the checkbox indicator. `class` | `string` | `""` | Additional CSS classes to style the checkbox indicator. `children` | `JSX.Element` | `undefined` | Content to render inside the checkbox indicator, which can be any valid JSX element. ##### Usage ```tsx import Checkbox from '@components/Basic/Checkbox/Checkbox'; import Icon from '@assets/check-mark.svg?component-solid'; const App = () => { return ( <> V-Sync Fullscreen Mode Motion Blur ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/checkbox/#implemented-navigation-actions] ## Checkbox: Implemented Navigation Actions The `Checkbox` component implements the following navigation actions by default: Action Name | Behavior `select` | Toggles the checkbox on/off You can extend the Checkbox with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import Checkbox from '@components/Basic/Checkbox/Checkbox'; console.log('Going back from checkbox'), 'select': () => console.log('Custom toggle logic') // Overrides default }} > Enable V-Sync ``` For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/checkbox/#guide] ## Checkbox: Guide (1/2) #### Retrive the Checkbox Value To retrieve the value assigned to the Checkbox component: - Use a `ref` to access the component instance - Use the `onChange` prop to respond when the checked state changes - Combine both to work with the value only when the checkbox is checked ##### Steps 1. Declare a `ref` variable with type `CheckboxRef` and pass it to the `Checkbox` component. 2. Provide a callback to the `onChange` prop to respond to state changes. 3. Inside the callback, access the checkbox value via the `ref` and act based on the checked state. ```tsx import Checkbox, { CheckboxRef } from '@components/Basic/Checkbox/Checkbox'; const App = () => { let checkboxRef!: CheckboxRef const getValue = (checked: boolean) => { if (checked) { // Log the value whenever the checkbox is checked console.log(checkboxRef.value); } } return ( <> Enable V-Sync ); }; export default App; ``` #### Set the value of the Checkbox Programmatically The `Checkbox` component lets you set the `checked` state through code. ##### Steps 1. Declare a `ref` variable with type `CheckboxRef` and pass it to the `Checkbox` component. 2. Call `ref.setChecked()` from anywhere (e.g., a keyboard event or external button) to set the checked state programmatically. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/checkbox/#guide] ## Checkbox: Guide (2/2) ```tsx import Checkbox, { CheckboxRef } from '@components/Basic/Checkbox/Checkbox'; const App = () => { let checkboxRef!: CheckboxRef const handleKeyPress = (e: KeyboardEvent) => { if (e.keyCode !== 13) return checkboxRef.setChecked(true); } return ( <> Enable V-Sync ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown-options/] ## Dropdown.Options The `Dropdown.Options` slot serves as the container for all the options within the `Dropdown` component. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown-options/#installation] ## Dropdown.Options: Installation Every component ships with the boilerplate. If you are working in your own project, add `Dropdown` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Dropdown ``` The CLI pulls in whatever `Dropdown` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown-options/#usage] ## Dropdown.Options: Usage To use `Dropdown.Options`, wrap it inside the `Dropdown` component. **index.tsx:** ```tsx import Dropdown from '@components/Basic/Dropdown/Dropdown'; red green blue ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown-options/#api] ## Dropdown.Options: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the dropdown options container element. `class` | `string` | `""` | Additional CSS classes to apply to the dropdown options container element. `children` | `JSX.Element` | `""` | The children of `Dropdown.Options` should include all the `Dropdown.Option` slots. `inverted-class` | `string` | `""` | CSS class to apply when the dropdown options are in an inverted position (e.g., opening upwards). --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown-options/#slots] ## Dropdown.Options: Slots (1/3) #### Dropdown.Option This slot is used to add a new option to the Dropdown. It also allows customization of the option’s appearance. **Note:** The `Dropdown.Option` must be used within the `Dropdown.Options` slot. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied directly to the dropdown option element. `class` | `string` | `""` | Additional CSS classes for the dropdown option element. `value` | `string` | `undefined` | The value associated with the dropdown option. `selected` | `boolean` | `false` | Marks the option as selected initially, when the component mounts. If the parent `Dropdown` is given a valid `value` prop, that value determines the selection instead and this prop is ignored. `disabled` | `boolean` | `false` | Indicates if the dropdown option is disabled. `class-selected` | `string` | `""` | Additional CSS classes applied when the dropdown option is selected. `class-disabled` | `string` | `""` | Additional CSS classes applied when the dropdown option is disabled. `children` | `JSX.Element` | `""` | Content of the option, used to render text, HTML, or JSX elements within the option. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown-options/#slots] ## Dropdown.Options: Slots (2/3) ```tsx import Dropdown from '@components/Basic/Dropdown/Dropdown'; const App = () => { return ( red green blue ); }; export default App; ``` **Note:** You can use the `Dropdown.Option` slot multiple times within the `Dropdown.Options` slot as needed. **Note:** The `selected` prop only sets the **initial** selection. To control the selection over time, use the `value` prop on the Dropdown instead — when a valid `value` is provided it takes precedence over `selected`. **Tip:** To dynamically render options, you can use an array and map over it: ```tsx const options = [ {value: 'option-1', text: 'Option 1', selected: true, disabled: false}, {value: 'option-2', text: 'Option 2', selected: false} ... ]; ... {options.map((option) => ( {option.text} ))} ``` Alternatively, you can use the SolidJS `For` component: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown-options/#slots] ## Dropdown.Options: Slots (3/3) ```tsx const options = [ {value: 'option-1', text: 'Option 1', selected: true, disabled: false}, {value: 'option-2', text: 'Option 2', selected: false} ... ]; ... {(option) => ( {option.text} )} ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown-options/#guide] ## Dropdown.Options: Guide #### Applying offset to dropdown options By default, the dropdown options will open below the trigger. If there isn’t enough space, they automatically open above the trigger. To customize the styles applied when the options are in an inverted position (opening upwards), use the `inverted-class` prop. When applying an offset, handle two states: normal and inverted. Since the options are positioned using percentages, adjust those values accordingly. ##### Steps 1. Add the `inverted-class` prop to the `Dropdown.Options` slot and set it to your custom CSS class. 2. Define the custom CSS class in your stylesheet to apply the desired styles when the options are inverted. ```css .dropdown-options { top: 125%; /* Adjust the offset as needed */ } .dropdown-options-inverted { bottom: 125%; /* Adjust the offset as needed */ } ``` ```tsx import Dropdown from '@components/Basic/Dropdown/Dropdown'; import style from './App.module.css'; const App = () => { return ( red green blue ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/] ## Dropdown The `Dropdown` component allows you to create a dropdown menu with selectable options. It works seamlessly with the `Dropdown.Options` and `Dropdown.Option` slots. For detailed information about the `Dropdown.Options` and `Dropdown.Option` slots, refer to the Dropdown.Options documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#installation] ## Dropdown: Installation Every component ships with the boilerplate. If you are working in your own project, add `Dropdown` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Dropdown ``` The CLI pulls in whatever `Dropdown` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#usage] ## Dropdown: Usage To implement a dropdown in your UI, wrap the `Dropdown.Options` and `Dropdown.Option` slots within the `Dropdown` component: **index.tsx:** ```tsx import Dropdown from '@components/Basic/Dropdown/Dropdown'; red green blue ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#api] ## Dropdown: API (1/3) #### Props --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#api] ## Dropdown: API (2/3) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `DropdownRef \| undefined` | `undefined` | A reference to the component, providing access to its methods and underlying HTML element for programmatic control. `disabled` | `boolean` | `false` | Disables the dropdown when set to `true`. `class-disabled` | `string` | `""` | Additional CSS classes to apply when the dropdown is disabled. `multiple` | `boolean` | `false` | Enables multi-select mode. When `true`, selecting an option toggles it on or off, the options panel stays open after a selection, and `onChange` reports an array of values. `value` | `string \| string[]` | `undefined` | The selected value(s) of the dropdown. Pass a `string` (or a `string[]` when `multiple` is enabled) to control or set the selection. The prop is reactive - updating it externally changes the selection. Values that don’t match a registered option are ignored. When provided, it takes precedence over the `selected` prop on `Dropdown.Option`. `onChange` | `(value: string \| string[]) => void` | `undefined` | Callback function triggered whenever the selection changes. Provides the selected option’s value, or an array of selected values when `multiple` is enabled. `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#api] ## Dropdown: API (3/3) Prop Name | Type | Default | Description `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the dropdown’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#ref-api] ## Dropdown: Ref API To interact with the `Dropdown` programmatically, you can use the `DropdownRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `selected` | `Accessor` | Read the currently selected option: `ref.selected()` returns the value. `selectedValues` | `Accessor` | Read all currently selected values when the dropdown is in `multiple` mode: `ref.selectedValues()` returns the array of values. `element` | `HTMLDivElement` | A reference to the dropdown’s root HTML element, useful for DOM access or styling. #### Methods Method | Parameters | Return Value | Description `selectOption` | `value: string` | `void` | Selects an option programmatically. In `multiple` mode, calling it with an already-selected value toggles it off. `deselectOption` | `value: string` | `void` | Deselects a single option by its value. `deselectAll` | `none` | `void` | Clears every selected option in one call, firing `onChange` once with the empty result. `toggle` | `isOpened: boolean` | `void` | Programmatically opens (`true`) or closes (`false`) the dropdown’s options panel. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#slots] ## Dropdown: Slots (1/5) #### Dropdown.Trigger The `Dropdown.Trigger` slot allows you to customize the dropdown’s trigger button, which toggles the dropdown’s open or closed state when clicked. Use this slot to modify the trigger’s appearance by applying custom styles or CSS classes. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the trigger element. `class` | `string` | `""` | Additional CSS classes to apply to the trigger element. ##### Usage ```tsx import Dropdown from '@components/Basic/Dropdown/Dropdown'; const App = () => { return ( red green blue ); }; export default App; ``` #### Dropdown.Placeholder The `Dropdown.Placeholder` slot allows you to display a placeholder when no option is selected in the dropdown. If this slot is not used, no placeholder will be shown by default. **Note:** To display the default placeholder with the text `Select an option`, include the `` as a direct child of the `` component. **Note:** To use a custom placeholder, include the `` slot with your desired content, such as `Select any option`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#slots] ## Dropdown: Slots (2/5) ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the placeholder element. `class` | `string` | `""` | Additional CSS classes to apply to the placeholder element. `children` | `JSX.Element` | `""` | Content to display when no option is selected, such as text or JSX. ##### Usage ```tsx import Dropdown from '@components/Basic/Dropdown/Dropdown'; const App = () => { return ( red green blue Select any option ); }; export default App; ``` #### Dropdown.Icon The `Dropdown.Icon` slot allows you to add or customize the icon displayed inside the dropdown’s trigger, typically on the right side. **Note:** To use the default icon, include the `` slot as a child of the `` component. **Note:** To use a custom icon, provide your desired content as children of the `Dropdown.Icon` slot: ```jsx ... ``` ##### Properties --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#slots] ## Dropdown: Slots (3/5) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the dropdown trigger’s icon element. `class` | `string` | `""` | Additional CSS classes to apply to the dropdown trigger’s icon element. `children` | `JSX.Element` | `""` | Custom content, such as text, HTML, or JSX, to render as the dropdown icon. ##### Usage ```tsx import Dropdown from '@components/Basic/Dropdown/Dropdown'; const App = () => { return ( red green blue ); }; export default App; ``` #### Dropdown.Track The `Dropdown.Track` slot enables you to customize the scroll track of the dropdown when the options overflow the container. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the dropdown’s track element. `class` | `string` | `""` | Additional CSS classes to apply to the dropdown’s track element. `children` | `JSX.Element` | `""` | Custom content, such as text, HTML, or JSX, to render inside the track. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#slots] ## Dropdown: Slots (4/5) ```tsx import Dropdown from '@components/Basic/Dropdown/Dropdown'; const App = () => { return ( red green blue ); }; export default App; ``` **Tip:** To hide the `Dropdown.Track`, you can set its `display` style to `none`: ```tsx ``` #### Dropdown.Handle The `Dropdown.Handle` slot lets you customize the scroll handle for the dropdown when the options overflow the container. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the handle element. `class` | `string` | `""` | Additional CSS classes to apply to the handle element. `children` | `JSX.Element` | `""` | Custom content, such as text, HTML, or JSX, to render inside the handle. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#slots] ## Dropdown: Slots (5/5) ```tsx import Dropdown from '@components/Basic/Dropdown/Dropdown'; const App = () => { return ( red green blue ); }; export default App; ``` **Tip:** To hide the `Dropdown.Handle`, set its `display` style to `none`: ```tsx ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#implemented-navigation-actions] ## Dropdown: Implemented Navigation Actions The `Dropdown` component implements the following navigation actions by default: Action Name | Behavior `select` | Opens the dropdown when closed. When open, collapses the dropdown (options handle selection) `back` | Closes the dropdown and returns focus to the trigger or anchor element You can extend the `Dropdown` with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import Dropdown from '@components/Basic/Dropdown/Dropdown'; console.log('Custom select behavior!'), 'back': () => console.log('Custom back behavior!') }} > red green blue ``` **Caution:** Every `Dropdown.Option` component is listening for the `select` action to handle option selection. This action cannot be overriden. For more information about navigation actions, check the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#guide] ## Dropdown: Guide (1/4) #### Retrieve the selected option’s value on change To capture the value of the selected option: - Use the `onChange` prop to handle changes in the selected option. ##### Steps 1. Pass a callback function to the `onChange` prop to handle state updates. 2. Access the selected option’s value through the `selected` parameter in the callback. ```tsx import Dropdown from '@components/Basic/Dropdown/Dropdown'; const App = () => { const handleSelectionChange = (selected: string) => { console.log(selected); }; return ( red green blue ); }; export default App; ``` #### Allow selecting multiple options To let users select more than one option at a time, enable the `multiple` prop. ##### Behavior - Clicking an option toggles it on or off instead of replacing the current selection. - The options panel stays open after a selection so several options can be picked in a row. - `onChange` receives an array of the selected values. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#guide] ## Dropdown: Guide (2/4) ```tsx import Dropdown from '@components/Basic/Dropdown/Dropdown'; const App = () => { const handleSelectionChange = (selected: string[]) => { console.log(selected); // e.g. ["red", "blue"] }; return ( red green blue ); }; export default App; ``` **Note:** In `multiple` mode, read the current selection with `ref.selectedValues()` and clear it with `ref.deselectAll()`. #### Control the selected value (two-way binding) The `value` prop is reactive: pass a signal to it and update that signal from `onChange` to keep your state and the dropdown in sync in both directions. - Updating the signal externally moves the selection (state → dropdown). - Selecting an option in the UI fires `onChange`, which updates the signal (dropdown → state). ##### Steps 1. Create a signal to hold the selected value. 2. Bind it to the `value` prop. 3. Update it from the `onChange` callback. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#guide] ## Dropdown: Guide (3/4) ```tsx import Dropdown from '@components/Basic/Dropdown/Dropdown'; import { createSignal } from 'solid-js'; const App = () => { const [selected, setSelected] = createSignal('red'); return ( <> setSelected(value as string)}> red green blue {/* Updating the signal here also moves the dropdown's selection */} ); }; export default App; ``` In `multiple` mode, bind `value` to a `string[]` signal instead. Any values that don’t match a registered option are filtered out: ```tsx const [selected, setSelected] = createSignal(['red', 'blue']); setSelected(value as string[])}> red green blue ``` **Note:** When `value` is provided, it is the source of truth for the selection and overrides the `selected` prop on individual `Dropdown.Option` slots. #### Programmatically set the selected option --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/dropdown/#guide] ## Dropdown: Guide (4/4) The `Dropdown` component allows you to programmatically update the selected option. ##### Steps 1. Create a `ref` variable of type `DropdownRef` and assign it to the `Dropdown` component. 2. Use the `ref.selectOption()` method to programmatically set a new selected option, such as in response to a button click or keyboard event. ```tsx import Dropdown, { DropdownRef } from '@components/Basic/Dropdown/Dropdown'; const App = () => { let dropdownRef!: DropdownRef; const handleKeyPress = (e: KeyboardEvent) => { if (e.keyCode !== 13) return dropdownRef.selectOption('green'); }; return ( red green blue ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/inline-text-block/] ## InlineTextBlock The `InlineTextBlock` component is used to create a text block element that can display all its children inline. It renders a `p` element with the `cohinline` attribute, allowing you to have text with images, for example, on a single line. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/inline-text-block/#installation] ## InlineTextBlock: Installation Every component ships with the boilerplate. If you are working in your own project, add `InlineTextBlock` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add InlineTextBlock ``` The CLI pulls in whatever `InlineTextBlock` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/inline-text-block/#usage] ## InlineTextBlock: Usage Using the `InlineTextBlock` component is straightforward. After importing it, you can include any child elements, such as text or images, inside the component. **index.tsx:** ```tsx import InlineTextBlock from '@components/Basic/InlineTextBlock/InlineTextBlock'; <> Text with image. ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/inline-text-block/#api] ## InlineTextBlock: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Styles applied directly to the root element of the component.. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `HTMLButtonElement \| undefined` | `undefined` | Obtains the component’s DOM element and assigns it to a variable, allowing direct access to the HTML element via the ref object. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/inline-text-block/#guide] ## InlineTextBlock: Guide #### Accessing the HTML element To access the HTML element of the component and make modifications, you can add a `ref` property to the inline text block. ```tsx import InlineTextBlock from '@components/Basic/InlineTextBlock/InlineTextBlock'; const App = () => { let ref: HTMLParagraphElement; return ( Text with image. ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/] ## Keybinds The `Keybinds` component is an easy way to set up keyboard + mouse binding logic in your UI. It works together with the `Keybind` component, which represents a single action slot. `Keybinds` provides context, conflict handling, and programmatic control. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#installation] ## Keybinds: Installation **Available in Gameface UI projects only:** `Keybinds` comes with the boilerplate and cannot be added to an existing project with the CLI. It depends on a generated type file, an icon-generation script, and the gamepad glyph assets that only exist in the full template, so an installed copy would not build. To use it, start from the boilerplate. The CLI documentation explains this in [components that need a full Gameface project](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/existing-projects/#components-that-need-a-full-gameface-project). --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#usage] ## Keybinds: Usage (1/2) Wrap all your `Keybind` items in a `Keybinds` component. Each `Keybind` needs an `action` and can optionally get an initial `value`. **index.tsx:** ```tsx import Keybinds from '@components/Basic/Keybinds/Keybinds'; import Keybind from '@components/Basic/Keybinds/Keybind'; ``` **Note:** If a `Keybind` does not have a `value` prop, it will be initialized with `null` (unbound). #### Dynamic Keybinds Another way to do it is to map over an array of objects and create a `Keybind` for each one: ```tsx const mappings = [ { action: "forward", value: "W" }, { action: "backward", value: "S" }, { action: "left", value: "A" }, { action: "right", value: "D" }, { action: "jump", value: null } ]; {(mapping) => } ``` #### With defaults You can also provide an initial bindings map to the `Keybinds` component via the `defaults` prop. This is useful if you want to load presets. ```tsx const mappings = { forward: "W", backward: "S", left: "A", right: "D", jump: null }; {(action) => } ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#usage] ## Keybinds: Usage (2/2) **Caution:** When using `defaults`, you still need to explictly declare each `Keybind` child with its corresponding `action`. The `value` prop can be omitted since it will be seeded from `defaults`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#api] ## Keybinds: API (1/3) #### Props Prop name | Type | Default | Description `defaults` | `Record` | `undefined` | Initial bindings map: `{ action: label }`. If omitted, children can seed themselves via their `value`. `placeholder` | `string` | `undefined` | Text shown in each `Keybind` when no key is bound. `listeningText` | `string` | `Press any key...` | Text to show while waiting for input. `overrides` | `Partial>` | `{}` | Object of custom key overrides. Include only the codes you want to change (e.g., `KeyW`, `ArrowLeft`, `Digit1`). See Mappings `conflictPolicy` | `'block' \| 'replace-existing' \| 'swap' \| 'allow-duplicates'` | `'allow-duplicates'` | How to resolve when a new binding collides with an existing one (see below). `ref` | `(ref: KeybindsRef) => void` | `undefined` | Exposes programmatic methods and the current bindings. `onConflict` | `(action: string, key: string \| null, conflictAction: string) => void` | `undefined` | Called when a conflict happens under any policy. `onChange` | `(prev: string \| null, next: string \| null, action: string) => void` | `undefined` | Called when a bind or unbind operation succeeds. `mode` | `gamepad` \| `keyboard` | `keyboard` | Sets the mode for the input. Use `gamepad` in order to accept and display gamepad buttons. `glyphOverrides` | `Partial \| JSX.Element>>` | `{}` | Object of custom display glyph overrides. Include only the gamepad values you want to change (e.g., `0`, `1`, `left.joystick`). See Glyphs Object #### Ref API --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#api] ## Keybinds: API (2/3) To interact with the `Keybinds` programmatically, you can use the `KeybindsRef` interface. This interface provides properties and methods to access and manipulate the component’s state. ##### Properties Property | Type | Description `bindings` | `Record` | The current state of the bindings map. Use to retrieve the up-to-date bindings object. ##### Methods Method | Parameters | Return Value | Description `bind` | `(action: string, newKey: string \| null)` | `void` | Programmatically bind an action. Applies the current `conflictPolicy`. `unbindKey` | `(key: string \| null)` | `void` | Unbinds **all** actions that currently use this key (no-op if `null`). `mapBindings` | `(bindings: Record)` | `void` | Bulk-apply bindings (clears existing, then binds each). Conflict policy still applies per entry. `clearAll` | `()` | `void` | Clears all keys by setting **every** action’s value to `null`. `reset` | `()` | `void` | Restores to the original baseline captured on mount: `defaults` if provided, otherwise whatever the children had seeded initially. #### Conflict policies When a user tries to bind a key that is already in use, one of the following policies will be applied: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#api] ## Keybinds: API (3/3) - `block`: The new binding is rejected, and the existing one remains unchanged. It displays a console warn. - `replace-existing`: The new binding replaces the existing one, unbinding the previous action. - `swap`: The new binding takes the place of the existing one, and the existing action is assigned to the key that was previously bound to the new action. - `allow-duplicates`: Both actions are allowed to share the same key. All policies will trigger the `onConflict` callback if provided to the component. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#keybind] ## Keybinds: Keybind (1/2) The `Keybind` component represents a single action slot. It must be a child of the `Keybinds` component. When clicked, it starts to listen for the user to press a key or mouse button to bind the associated action. #### Props Prop name | Type | Default | Description `action` | `string` | `undefined` | The action that will have a key bound to it. `value` | `string \| undefined` | `undefined` | The value associated with the keybind by default. If omitted, it will be `null`. The string provided must match the label from the mappings object, unless overridden. If the `mode` prop is set to `gamepad` the value must match any of the values or aliases from the Glyph Object `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the keybind. See Implemented Navigation Actions for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the button’s actions will execute. Can be a CSS selector or HTMLElement. #### Implemented Navigation Actions The `Keybind` component implements the following navigation actions by default: Action Name | Behavior `select` | Begin listening for gamepad input You can extend the `Keybind` with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import Keybind from '@components/Basic/Keybinds/Keybind'; console.log('custom action')}}/> ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#keybind] ## Keybinds: Keybind (2/2) For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#gamepad-support] ## Keybinds: Gamepad Support 2.0.0 (1/4) With the introduction of the Navigation component, the `Keybinds` component now supports gamepad input as well. To enable gamepad support, set the `mode` prop to `gamepad`. When in gamepad mode, the component will listen for gamepad button presses instead of keyboard/mouse input. Internally, the gamepad buttons are identified and stored by the [Gamepad API standard button indices](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/buttons), while the axes are identified by custom aliases (e.g., `left.joystick.up`, `right.joystick.left`, etc.). See the Glyphs object table for the full list of supported gamepad button codes and axis aliases. For easier readability, you can use the same button codes and axis aliases used by the [Interaction Manager Gamepad Class](https://frontend-tools.coherent-labs.com/interaction-manager/features/gamepad/#options). These will resolve to the correct button indices internally. #### Usage In order for the `Keybind` component to listen for a gamepad button press, the `Keybind` component must be focused via the `Navigation` component system. The easiest way is to wrap the `Keybind` components with a `Navigation.Area` component. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#gamepad-support] ## Keybinds: Gamepad Support 2.0.0 (2/4) ```tsx import Keybinds from '@components/Basic/Keybinds/Keybinds'; import Keybind from '@components/Basic/Keybinds/Keybind'; import Navigation from '@components/Utility/Navigation/Navigation'; const App = () => { return ( ); }; export default App; ``` **Duplicate bindings:** Binding a value of `xbox.a` and `face-button-down` or even `0` will result in the same button trying to be bound. In which case it will be treated as a conflict. #### Displayed glyphs When displaying the bound keys, the component will render the corresponding glyphs for the gamepad buttons. The default glyphs are based on the standard Xbox controller layout and are displayed by the Image component. You can override the default glyphs by providing a custom `glyphOverrides` prop to the `Keybinds` component and providing your own components or elements for the desired buttons. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#gamepad-support] ## Keybinds: Gamepad Support 2.0.0 (3/4) ```tsx import Keybinds from '@components/Basic/Keybinds/Keybinds'; import Keybind from '@components/Basic/Keybinds/Keybind'; const App = () => { const GLYPHS: GlyphOverrides = { '0': Image.icons.gamepad.ps5.cross, '1': Image.icons.gamepad.ps5.circle, '2': , '3': , } return ( ); }; export default App; ``` Now the `Keybind` component with `xbox.a` value will display the ps5 cross glyph instead of the default xbox a glyph. **Note:** When overriding glyphs, make sure to use the exact same gamepad button codes and axis aliases as specified in the Glyphs object table. #### Styling the gamepad glyphs If you wish to provide custom styling to the displayed glyphs such as changing the `width/height` of the displayed image, you can do so by overriding the glyph via the `glyphOverrides` prop and providing your own component or element with the desired styles. For example, to keep the default xbox glyphs but change their size, you can do the following: ```scss .gamepad-glyph { width: 5vmax; height: 5vmax; } ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#gamepad-support] ## Keybinds: Gamepad Support 2.0.0 (4/4) ```tsx const GLYPHS: GlyphOverrides = { '0': , '1': , '2': , '3': , } ``` **Tip:** We recommend using the Image component for rendering the glyphs. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#guide] ## Keybinds: Guide (1/6) #### Retrieving current bindings object When users change keybinds, you will likely want to save the new bindings map somewhere. You can do this by accessing the `bindings` property. When accessed it will return the up to date object with the currently set bindings. To achieve this, you need to use a ref: 1. Create a ref variable with the type `KeybindsRef`. 2. Pass the ref variable to the `Keybinds` component via the `ref` prop. 3. Access the `bindings` property on the ref variable whenever you need to retrieve the current bindings object. 4. Optionally, you can use the `onChange` callback to be notified whenever a user successfully changes a binding. ```tsx import Keybinds, { KeybindsRef } from '@components/Basic/Keybinds/Keybinds'; import Keybind from '@components/Basic/Keybinds/Keybind'; const App = () => { let keybindsRef!: KeybindsRef; const retrieveBindings = (prev: string | null, next: string | null, action: string) => { console.log(`Changed "${action}" from "${prev}" to "${next}"`); console.log(keybindsRef.bindings); } return ( ); }; export default App; ``` #### Reset to defaults --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#guide] ## Keybinds: Guide (2/6) You can reset all keybinds to their original state by calling the `reset` method on the ref. This will restore the internal state to the initial `defaults` if provided, otherwise whatever the children had seeded initially when first rendered. To achieve this, you need to use a ref: 1. Create a ref variable with the type `KeybindsRef`. 2. Pass the ref variable to the `Keybinds` component via the `ref` prop. 3. Reset the keybinds by calling the `reset` method on the ref variable whenever needed. ```tsx import Keybinds, { KeybindsRef } from '@components/Basic/Keybinds/Keybinds'; import Keybind from '@components/Basic/Keybinds/Keybind'; const App = () => { let keybindsRef!: KeybindsRef; const resetToDefaults = () => keybindsRef.reset(); return ( ); }; export default App; ``` In this case because no `defaults` prop was provided, it will reset to the original values seeded by the children: `forward: "W"` and `backward: "Down"`. #### Programmatically binding/unbinding keys You can programmatically bind or unbind keys by using the `bind` and `unbindKey` methods on the ref. To achieve this, you need to use a ref: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#guide] ## Keybinds: Guide (3/6) 1. Create a ref variable with the type `KeybindsRef`. 2. Pass the ref variable to the `Keybinds` component via the `ref` prop. 3. Rebind a key to an action by calling the `bind` method on the ref variable, passing the action and the new key as arguments. 4. Unbind a key from all actions by calling the `unbindKey` method on the ref variable, passing the key to unbind as an argument. ```tsx import Keybinds, { KeybindsRef } from '@components/Basic/Keybinds/Keybinds'; import Keybind from '@components/Basic/Keybinds/Keybind'; const App = () => { let keybindsRef!: KeybindsRef; const rebindForward = () => keybindsRef.bind('forward', 'Up'); const unbindBackward = () => keybindsRef.unbindKey('Down'); return ( <> ); }; export default App; ``` If operations are successful, the `onChange` callback will be triggered if provided. #### Triggering a function when conflicts happen You can be notified when a conflict happens by providing the `onConflict` callback to the `Keybinds` component. This can be useful if you want to display a message to the user or prompt them for an action. The `onConflict` callback will return the following parameters: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#guide] ## Keybinds: Guide (4/6) - `action`: The action that the user is trying to bind. - `key`: The key that the user is trying to bind. - `conflictAction`: The action that is currently bound to the key. To achieve this, you need to provide a function to the `onConflict` prop of the `Keybinds` component. ```tsx import Keybinds from '@components/Basic/Keybinds/Keybinds'; import Keybind from '@components/Basic/Keybinds/Keybind'; const App = () => { let keybindsRef!: KeybindsRef; const handleConflict = (action: string, key: string | null, conflictAction: string) => { console.log(`Conflict detected! Tried to bind "${key}" to "${action}", but it's already bound to "${conflictAction}".`); } return ( <> ); }; export default App; ``` #### Applying presets You can apply a preset bindings map by using the `mapBindings` method on the ref. This is useful if you want to allow users to switch between different keybind presets. To achieve this, you need to use a ref: 1. Create a ref variable with the type `KeybindsRef`. 2. Pass the ref variable to the `Keybinds` component via the `ref` prop. 3. Apply a new bindings map by calling the `mapBindings` method on the ref variable, passing the new bindings object as an argument. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#guide] ## Keybinds: Guide (5/6) ```tsx import Keybinds, { KeybindsRef } from '@components/Basic/Keybinds/Keybinds'; import Keybind from '@components/Basic/Keybinds/Keybind'; const App = () => { let keybindsRef!: KeybindsRef; const preset = { forward: "Up", backward: "Down", left: "Left", right: "Right", jump: null }; const changePreset = () => keybindsRef.mapBindings(preset); return ( <> ); }; export default App; ``` You can see an extended example of presets in the Menu UI view located at `src/views/menu/Menu.tsx`. #### Key label overrides (custom key display) In order to provide custom values for some keys you need to customize how keys are displayed. To achieve that, do the following. 1. Create an object where the keys are the codes you want to override and the values are the custom labels you want to display. 2. Pass the object to the `overrides` prop of the `Keybinds` component. 3. Now the `Keybinds` component will consider you custom labels as valid display values. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#guide] ## Keybinds: Guide (6/6) ```tsx import Keybinds, { KeybindsRef } from '@components/Basic/Keybinds/Keybinds'; import Keybind from '@components/Basic/Keybinds/Keybind'; const App = () => { const overrides = { "ArrowUp": "Up", "ArrowDown": "Down", "Backquote": "`", "BracketLeft": "[", "BracketRight": "]", "0": "Mouse Left", "2": "Mouse Right", "WheelUp": "Wheel Up", }; return ( <> ); }; export default App; ``` **Caution:** Overrides must follow the exact casing of the codes as specified in the Reference table. For example, use `ArrowUp` instead of `arrowup` or `ARROWUP`. **Caution:** Overrides are applied when the component first mounts. Changing the `overrides` prop later will not update existing keybinds. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#reference] ## Keybinds: Reference (1/4) #### Mappings object The `Keybinds` component comes with a default mapping object that translates common `KeyboardEvent.code` and mouse button codes to user-friendly labels. The mappings object uses [KeyboardEvent.code](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values) for keyboard mappings and [MouseEvent.button](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button#value) for mouse button mappings. The object is located at `src/components/Basic/Keybinds/mappings.ts`. ##### Keyboard --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#reference] ## Keybinds: Reference (2/4) Code | Label KeyA | A KeyB | B KeyC | C KeyD | D KeyE | E KeyF | F KeyG | G KeyH | H KeyI | I KeyJ | J KeyK | K KeyL | L KeyM | M KeyN | N KeyO | O KeyP | P KeyQ | Q KeyR | R KeyS | S KeyT | T KeyU | U KeyV | V KeyW | W KeyX | X KeyY | Y KeyZ | Z Digit0 | 0 Digit1 | 1 Digit2 | 2 Digit3 | 3 Digit4 | 4 Digit5 | 5 Digit6 | 6 Digit7 | 7 Digit8 | 8 Digit9 | 9 F1 | F1 F2 | F2 F3 | F3 F4 | F4 F5 | F5 F6 | F6 F7 | F7 F8 | F8 F9 | F9 F10 | F10 F11 | F11 F12 | F12 F13 | F13 F14 | F14 F15 | F15 F16 | F16 F17 | F17 F18 | F18 F19 | F19 F20 | F20 F21 | F21 F22 | F22 F23 | F23 F24 | F24 Numpad0 | Num 0 Numpad1 | Num 1 Numpad2 | Num 2 Numpad3 | Num 3 Numpad4 | Num 4 Numpad5 | Num 5 Numpad6 | Num 6 Numpad7 | Num 7 Numpad8 | Num 8 Numpad9 | Num 9 NumpadAdd | \+ NumpadSubtract | \- NumpadMultiply | \* NumpadDivide | / NumpadDecimal | . NumpadComma | , NumpadEnter | Num Enter NumpadEqual | Num = Backquote | \` Minus | \- Equal | \= BracketLeft | \[ BracketRight | ] Backslash | \\ Semicolon | ; Quote | ’ Comma | , Period | . Slash | / ShiftLeft | L Shift ShiftRight | R Shift ControlLeft | L Ctrl ControlRight | R Ctrl AltLeft | L Alt AltRight | R Alt MetaLeft | L Meta MetaRight | R Meta Escape | Esc Tab | Tab CapsLock | Caps Space | Space Enter | Enter Backspace | Back Delete | Del Insert | Ins Home | Home End | End PageUp | PgUp PageDown | PgDn ArrowUp | Up ArrowDown | Down ArrowLeft | Left ArrowRight | Right PrintScreen | PrtSc ScrollLock | Scroll Pause | Pause ContextMenu | Menu NumLock | NumLock AudioVolumeMute | Mute AudioVolumeDown | Vol- AudioVolumeUp | Vol+ MediaTrackNext | Next --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#reference] ## Keybinds: Reference (3/4) Code | Label MediaTrackPrevious | Prev MediaStop | Stop MediaPlayPause | Play/Pause BrowserBack | BrowserBack BrowserForward | BrowserForward BrowserRefresh | BrowserRefresh BrowserStop | BrowserStop BrowserSearch | BrowserSearch BrowserFavorites | BrowserFav BrowserHome | BrowserHome ##### Mouse Buttons Code | Label 0 | LMB 1 | MMB 2 | RMB 3 | BMB 4 | FMB ##### Mouse Wheel Code | Label WheelUp | Wheel Up WheelDown | Wheel Down #### Glyphs object The `Keybinds` component comes with a default glyphs object that maps gamepad button codes to their corresponding glyph components for display purposes. The glyphs object is located at `src/components/Basic/Keybinds/glyphs.ts`. You can override the glyphs you want to display custom `Components` or `HTMLElements` by providing a custom `glyphOverrides` prop to the `Keybinds` component. Keep in mind that you should use the exact same gamepad button codes and axis aliases as specified below. ##### Buttons (Indices) Code | Standard Xbox | Standard PlayStation 0 | A | Cross 1 | B | Circle 2 | X | Square 3 | Y | Triangle 4 | LB (Bumper) | L1 5 | RB (Bumper) | R1 6 | LT (Trigger) | L2 7 | RT (Trigger) | R2 8 | View (Back) | Create/Share 9 | Menu (Start) | Options 10 | Left Stick Press (L3) | L3 11 | Right Stick Press (R3) | R3 12 | D-Pad Up | D-Pad Up 13 | D-Pad Down | D-Pad Down 14 | D-Pad Left | D-Pad Left 15 | D-Pad Right | D-Pad Right 16 | Guide / Share | PS Button ##### Joysticks aliases --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/keybinds/#reference] ## Keybinds: Reference (4/4) Code | Description `left.joystick` | The entire Left Analog Stick `left.joystick.up` | Left Stick Up direction `left.joystick.down` | Left Stick Down direction `left.joystick.left` | Left Stick Left direction `left.joystick.right` | Left Stick Right direction `right.joystick` | The entire Right Analog Stick `right.joystick.up` | Right Stick Up direction `right.joystick.down` | Right Stick Down direction `right.joystick.left` | Right Stick Left direction `right.joystick.right` | Right Stick Right direction --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/number-input/] ## NumberInput The NumberInput component is similar to TextInput but is specifically designed for numeric input. It ensures that only valid numbers can be entered and includes optional increment and decrement controls for adjusting the value. The component ensures numeric safety (preserving formatting, clamping min/max), and exposes utility methods via `ref` for programmatic changes. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/number-input/#installation] ## NumberInput: Installation Every component ships with the boilerplate. If you are working in your own project, add `NumberInput` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add NumberInput ``` The CLI pulls in whatever `NumberInput` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/number-input/#usage] ## NumberInput: Usage To use the `NumberInput` component, simply import it and pass any required props. **index.tsx:** ```tsx import NumberInput from '@components/Basic/Input/NumberInput/NumberInput'; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/number-input/#api] ## NumberInput: API (1/2) #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `NumberInputRef \| undefined` | `undefined` | A reference to the component that gives you access to its methods and the underlying HTML element. Useful if you need to set the value of the input programmatically. `value` | `string \| number` | `""` | The value of the input. Updating this prop is reflected in the input (clamped to `min`/`max`), allowing it to be controlled. Also sets the initial value. `min` | `number` | `undefined` | Minimum value that can be entered or selected. `max` | `number` | `undefined` | Maximum value that can be entered or selected. `step` | `number` | `1` | Increment/decrement step for buttons. `disabled` | `boolean` | `false` | Disables the input if set to true. `class-disabled` | `string` | `undefined` | Optional class to apply when the input is disabled. `readonly` | `boolean` | `false` | Specifies if the input is only able to be read. If set to true, the input will not accept values. `onChange` | `(value: string \| number) => void` | `undefined` | A function that is called every time the input’s value has changed. It can be used to retrieve the up to date value of the input. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/number-input/#api] ## NumberInput: API (2/2) Prop Name | Type | Default | Description `delay` | `number \| boolean` | `undefined` | When set, debounces the `onChange` callback by the given amount in milliseconds — it fires once typing pauses for that duration instead of on every keystroke. If set to `true`, the default delay of `250ms` is used. `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the input’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/number-input/#ref-api] ## NumberInput: Ref API To interact with the `NumberInput` programmatically, you can use the `NumberInputRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the input’s root HTML element, useful for DOM access or styling. `input` | `HTMLInputElement` | A reference to the internal input element. `value` | `Accessor` | Returns the current value of the input reactively. Use `value()`to read the latest input. #### Methods Method | Parameters | Return Value | Description `changeValue` | `newValue: number` | `void` | Programmatically sets a new value in the input field. `clear` | None | `void` | Clears the current value of the input. `increaseValue` | None | `void` | Increases value by the specified step (default is 1). `decreaseValue` | None | `void` | Decreases value by the specified step (default is 1). --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/number-input/#slots] ## NumberInput: Slots (1/3) #### NumberInput.IncreaseControl Defines a button that increases the input’s value. Can be positioned either before or after the input field. ##### Properties Prop Name | Type | Default | Description `position` | `before` \| `after` | `"after"` | Determines whether the button appears before or after the input field. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied directly to the visibility button container. `class` | `string` | `""` | Additional CSS classes for styling the button. `children` | `JSX.Element` | `""` | Custom content to override the default icons. ##### Usage ```tsx import NumberInput from '@components/Basic/NumberInput/NumberInput'; const App = () => { return ( + ); }; export default App; ``` #### NumberInput.DecreaseControl Defines a button that decreases the input’s value. Can be positioned either before or after the input field. ##### Properties Prop Name | Type | Default | Description `position` | `before` \| `after` | `"after"` | Determines whether the button appears before or after the input field. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied directly to the visibility button container. `class` | `string` | `""` | Additional CSS classes for styling the button. `children` | `JSX.Element` | `""` | Custom content to override the default icons. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/number-input/#slots] ## NumberInput: Slots (2/3) ```tsx import NumberInput from '@components/Basic/NumberInput/NumberInput'; const App = () => { return ( - ); }; export default App; ``` #### NumberInput.Input Used to override or extend the internal input element. This gives you full control over the input’s look and behavior. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the input element. `class` | `string` | `""` | Additional CSS classes to style the input element. ##### Usage ```tsx import NumberInput from '@components/Basic/NumberInput/NumberInput'; const App = () => { return ( ); }; export default App; ``` #### TextInput.Placeholder Use this to define a placeholder content which will be displayed when the input has no value. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the input element. `class` | `string` | `""` | Additional CSS classes to style the input element. `children` | `JSX.Element` | `""` | Content to be rendered inside the placeholder slot. This can be used to add content as the input’s placeholder. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/number-input/#slots] ## NumberInput: Slots (3/3) ```tsx import NumberInput from '@components/Basic/NumberInput/NumberInput'; const App = () => { return ( Enter nickname ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/number-input/#implemented-navigation-actions] ## NumberInput: Implemented Navigation Actions The `NumberInput` component implements the following navigation actions by default: Action Name | Behavior `select` | Focuses the input element, making it ready for typing `back` | Blurs the input element, exiting typing mode `move-up`, `move-down` | Increases the value of the input by the `step` prop’s value You can extend the `NumberInput` with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import NumberInput, { NumberInputRef } from '@components/Basic/NumberInput/NumberInput'; const App = () => { let inputRef!: NumberInputRef; return ( console.log('Custom select action'), 'back': () => console.log('Custom back action'), }} /> ); }; ``` For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/number-input/#guide] ## NumberInput: Guide #### Increase or decrease value programmatically You can programmatically control the `NumberInput` value using its `ref`, making it easy to respond to keyboard events like arrow key presses. ##### Steps 1. Declare a `ref` variable with type `NumberInputRef `and pass it to the `NumberInput` component. 2. Call `ref.increaseValue()` or `ref.decreaseValue()` directly as needed. ```tsx import NumberInput, { NumberInputRef } from '@components/Basic/NumberInput/NumberInput'; const App = () => { let inputRef!: NumberInputRef; const handleKeyDown = (e: KeyboardEvent) => { if (!inputRef) return; if (e.keyCode === 38) { inputRef.increaseValue(); } else if (e.keyCode === 40) { inputRef.decreaseValue(); } }; return (
); }; export default App; ``` #### Other Guides All other usage patterns — like retrieving and setting values, or clearing the input — are identical to the `TextInput` component and can be seen here **Caution:** When following those examples, make sure to use `NumberInputRef` instead of `TextInputRef` when working with the ref. This ensures access to the correct methods. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/pagination/] ## Pagination The `Pagination` component provides a UI control for navigating between multiple pages. It supports optional numbered indicators, looping behavior, and customizable navigation controls. It’s ideal for interfaces such as menus, level selectors, or any UI where page-based navigation is required. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/pagination/#installation] ## Pagination: Installation Every component ships with the boilerplate. If you are working in your own project, add `Pagination` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Pagination ``` The CLI pulls in whatever `Pagination` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/pagination/#usage] ## Pagination: Usage To use `Pagination`, specify the total number of pages with `pageSize` and the current page index with `pageIndex`. **index.tsx:** ```tsx import Pagination from '@components/Basic/Pagination/Pagination'; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/pagination/#api] ## Pagination: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `pageSize` | `number` | **required** | Total number of pages. `pageIndex` | `number` | **required** | The currently selected page index (1-based). `loop` | `boolean` | `false` | Enables wrap-around navigation from last to first page and vice versa. `hasNumbers` | `boolean` | `false` | If true, displays page numbers inside each page indicator. `ref` | `PaginationRef \| undefined` | `undefined` | Provides access to the pagination element and control methods. `onChange` | `(index: number) => void` | `undefined` | Called whenever the selected page changes, providing the new index. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the component’s actions will execute. Can be a CSS selector or HTMLElement. **Caution:** The `pageIndex` prop is 1-based, meaning the first page is represented by `1`, the second by `2`, and so on. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/pagination/#ref-api] ## Pagination: Ref API To interact with the `Pagination` programmatically, you can use the `PaginationRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | The root DOM element of the pagination component. `pageIndex` | `Accessor` | The current page index. `pageSize` | `Accessor` | The total number of pages. #### Methods Method | Parameters | Return Value | Description `changeIndex` | `index: number` | `void` | Programmatically change to a specific page. `nextPage` | None | `void` | Navigate to the next page. `previousPage` | None | `void` | Navigate to the previous page. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/pagination/#slots] ## Pagination: Slots (1/3) #### Pagination.Control Use `Pagination.Control` to customize the visual appearance of the left/right arrow buttons. By default, the control consists of two arrow buttons for navigating to the previous or next page. **Note:** The right arrow is a rotated version of the left arrow (rotated 180 degrees). Keep this in mind when implementing a custom control. You only need to define the left arrow in the slot, as the right arrow will automatically be a rotated duplicate. You can apply additional CSS classes and styles to modify the appearance of the default arrows. If you want to replace the default arrows with a custom control, you can provide `children` using any valid JSX syntax. **Note:** If the `loop` option is not enabled on the `Pagination` component, the controls will be hidden/disabled when the first or last page is selected. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply to the default arrow elements. `class` | `string` | `""` | Additional CSS classes for the default arrow elements. `children` | `JSX.Element` | `""` | Custom content to replace the default arrow controls. `hidden-class` | `string` | `""` | CSS class to override the default behavior when the control is hidden. If `loop` is not enabled, the left control will be hidden/disabled when the first option is selected, and the right control will behave similarly for the last option. ##### Usage ```css .control-hidden { pointer-events: none; opacity: 0.1; } ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/pagination/#slots] ## Pagination: Slots (2/3) **Tip:** To completely hide the control when no other options are available, you can use `display: none`: ```css .control-hidden { display: none; } ``` ```tsx import Pagination from '@components/Basic/Pagination/Pagination'; const App = () => { return ( ); }; ``` ##### Usage with custom control ```tsx import Pagination from '@components/Basic/Pagination/Pagination'; import MyArrow from '@assets/icons/my-arrow.svg?component-solid'; const App = () => { return ( ); }; ``` #### Pagination.Item The `Pagination.Item` slot allows you to customize the appearance of each individual page indicator (dot, number, etc.). By default, each item is rendered as a simple clickable circle. You can use this slot to style them with custom colors, shapes, and sizes. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to every item. `class` | `string` | `""` | Additional CSS classes for styling the pagination items. `selected-class` | `string` | `""` | CSS class to override the default styles of the selected item. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/pagination/#slots] ## Pagination: Slots (3/3) ```tsx import Pagination from '@components/Basic/Pagination/Pagination'; const App = () => { return ( ); }; export default App; ``` **Note:** This slot customizes all items. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/pagination/#guide] ## Pagination: Guide (1/2) #### Handle page changes Use the `onChange` prop to react to user navigation. This callback is triggered whenever the active page changes, and it receives the updated page index as a parameter. ##### Steps 1. Pass a callback function to the `onChange` prop. 2. Use the page index in the callback to trigger data fetching or other logic. ```tsx import Pagination from '@components/Basic/Pagination/Pagination'; const App = () => { const fetchPageData = (page: number) => { // dynamically fetch the data console.log('Page changed to:', page); } return ( ) }; export default App; ``` #### Programmatically change the page You can also control the pagination programmatically using a component `ref`. This is useful when integrating keyboard, gamepad, or other custom navigation systems. 1. Declare a ref of type `PaginationRef` and pass it to the Pagination component. 2. Call `ref.nextPage()` or `ref.previousPage()` in response to keyboard events. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/pagination/#guide] ## Pagination: Guide (2/2) ```tsx import { onMount } from 'solid-js'; import Pagination, { PaginationRef } from '@components/Basic/Pagination/Pagination'; const App = () => { let ref!: PaginationRef; const handleKeydown = (e: KeyboardEvent) => { if (e.keyCode === 37) { // Left arrow ref.previousPage(); } else if (e.keyCode === 39) { // Right arrow ref.nextPage(); } }; onMount(() => { window.addEventListener('keydown', handleKeydown); // Cleanup on unmount return () => window.removeEventListener('keydown', handleKeydown); }); return ( console.log('Page:', page)} /> ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/password-input/] ## PasswordInput The `PasswordInput` component is an input field designed specifically for handling password values.\ It extends the base behavior of TextInput and includes a dedicated slot for a **visibility toggle button**, allowing users to show or hide the password content. Like `TextInput`, it supports various slots for injecting UI elements before or after the input, and for customizing the input directly. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/password-input/#installation] ## PasswordInput: Installation Every component ships with the boilerplate. If you are working in your own project, add `PasswordInput` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add PasswordInput ``` The CLI pulls in whatever `PasswordInput` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/password-input/#usage] ## PasswordInput: Usage To use the `PasswordInput` component, simply import it and pass any required props. **index.tsx:** ```tsx import PasswordInput from '@components/Basic/Input/PasswordInput/PasswordInput'; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/password-input/#api] ## PasswordInput: API (1/2) #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `PasswordInputRef \| undefined` | `undefined` | A reference to the component that gives you access to its methods and the underlying HTML element. Useful if you need to set the value of the input programmatically. `value` | `string` | `""` | The value of the input. Updating this prop is reflected in the input, allowing it to be controlled. Also sets the initial value. `disabled` | `boolean` | `false` | Disables the input if set to true. `readonly` | `boolean` | `false` | Specifies if the input is only able to be read. If set to true, the input will not accept values. `max-symbols` | `number` | `undefined` | Maximum number of symbols the input can accept. `class-disabled` | `string` | `undefined` | Optional class to apply when the input is disabled. `onChange` | `(value: string) => void` | `undefined` | A function that is called every time the input’s value has changed. It can be used to retrieve the up to date value of the input. `delay` | `number \| boolean` | `undefined` | When set, debounces the `onChange` callback by the given amount in milliseconds — it fires once typing pauses for that duration instead of on every keystroke. If set to `true`, the default delay of `250ms` is used. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/password-input/#api] ## PasswordInput: API (2/2) Prop Name | Type | Default | Description `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the input’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/password-input/#ref-api] ## PasswordInput: Ref API To interact with the `PasswordInput` programmatically, you can use the `PasswordInputRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the input’s root HTML element, useful for DOM access or styling. `input` | `HTMLInputElement` | A reference to the internal input element. `value` | `Accessor` | The current value of the input. Use `value()` to get the latest value. `visible` | `Accessor` | Indicates whether the password is currently visible. Use `visible()` to check. #### Methods Method | Parameters | Return Value | Description `changeValue` | `newValue: string` | `void` | Programmatically sets a new value in the input field. `clear` | None | `void` | Clears the current value of the input. `show` | None | `void` | Programmatically shows the value of the password input. `hide` | None | `void` | Programmatically hides the value of the password input. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/password-input/#slots] ## PasswordInput: Slots (1/3) #### PasswordInput.Before Allows the injection of content before the input element — useful for icons, labels, or additional UI elements. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the before slot container. `class` | `string` | `""` | Additional CSS classes to style the before slot container. `children` | `JSX.Element` | `""` | Content to be rendered inside the before slot. This can be used to add custom elements or styles. ##### Usage ```tsx import PasswordInput from '@components/Basic/PasswordInput/PasswordInput'; import Icon from @assets/icon.svg?component-solid; const App = () => { return ( ); }; export default App; ``` #### PasswordInput.After Allows the injection of content after the input element — ideal for suffixes, icons, or clear buttons. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the after slot container. `class` | `string` | `""` | Additional CSS classes to style the after slot container. `children` | `JSX.Element` | `""` | Content to be rendered inside the after slot. This can be used to add custom elements or styles. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/password-input/#slots] ## PasswordInput: Slots (2/3) ```tsx import PasswordInput from '@components/Basic/PasswordInput/PasswordInput'; import BinIcon from @assets/icon.svg?component-solid; const App = () => { return ( ); }; export default App; ``` #### PasswordInput.Input Used to override or extend the internal input element. This gives you full control over the input’s look and behavior. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the input element. `class` | `string` | `""` | Additional CSS classes to style the input element. ##### Usage ```tsx import PasswordInput from '@components/Basic/PasswordInput/PasswordInput'; const App = () => { return ( ); }; export default App; ``` #### PasswordInput.VisibilityButton The `VisibilityButton` slot allows you to add a toggle button that shows or hides the password. By default, it renders a visibility icon (eye / eye-slash), but you can fully customize it by passing your own content by providing children isnide the slot component. **Note:** If `VisibilityButton` is used, it overrides the `Before` or `After` slots, depending on the position of the button. You can’t use both at the same time. ##### Properties --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/password-input/#slots] ## PasswordInput: Slots (3/3) Prop Name | Type | Default | Description `position` | `before` \| `after` | `"after"` | Determines whether the button appears before or after the input field. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied directly to the visibility button container. `class` | `string` | `""` | Additional CSS classes for styling the button. `children` | `JSX.Element` | `""` | Custom content to override the default visibility toggle icons. ##### Usage ```tsx import PasswordInput from '@components/Basic/PasswordInput/PasswordInput'; const App = () => { return ( ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/password-input/#implemented-navigation-actions] ## PasswordInput: Implemented Navigation Actions The `PasswordInput` component implements the following navigation actions by default: Action Name | Behavior `select` | Focuses the input element, making it ready for typing `back` | Blurs the input element, exiting typing mode You can extend the `PasswordInput` with additional navigation actions or override the default behavior using the `onAction` prop. For example, you can bind the visibility toggle to a custom action like: ```tsx import PasswordInput, { PasswordInputRef } from '@components/Basic/PasswordInput/PasswordInput'; const App = () => { let inputRef!: PasswordInputRef; return ( { inputRef.visible() ? inputRef.hide() : inputRef.show(); } }} /> ); }; ``` For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/password-input/#guide] ## PasswordInput: Guide #### Toggle input visibility programmatically You can control the visibility of the password field programmatically using the component’s ref. This is useful when you want to trigger visibility toggling from external events like keypresses or buttons. ##### Steps 1. Declare a `ref` variable with type `PasswordInputRef` and pass it to the `PasswordInput` component. 2. Call `ref.show()` or `ref.hide()` to change the visibility. 3. Use `ref.visible()` to check whether the password is currently shown. ```tsx import PasswordInput { PasswordInputRef } from '@components/Basic/PasswordInput/PasswordInput'; const App = () => { let inputRef: PasswordInputRef; const toggleVisiblity = (e: KeyboardEvent) => { if (e.keyCode !== 13) return inputRef!.visible() ? inputRef!.hide() : inputRef!.show(); }; return ( <> ); }; export default App; ``` #### Other Guides All other usage patterns — like retrieving and setting values, or clearing the input — are identical to the `TextInput` component and can be seen here **Caution:** When following those examples, make sure to use `PasswordInputRef` instead of `TextInputRef` when working with the ref. This ensures access to the additional `show()`, `hide()`, and `visible()` methods. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio-button/] ## Radio.Button The `Radio.Button` slot represents a single option within a `Radio`. It renders a clickable control with a label. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio-button/#installation] ## Radio.Button: Installation Every component ships with the boilerplate. If you are working in your own project, add `RadioGroup` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add RadioGroup ``` The CLI pulls in whatever `RadioGroup` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio-button/#usage] ## Radio.Button: Usage To create a `Radio.Button` you need to wrap it in the `Radio` component and provide a value to it. You must also provide the `selected` prop to the `Radio.Button` you wish to be selected by default. **index.tsx:** ```tsx import Radio from '@components/Basic/RadioGroup/Radio'; <> red green blue ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio-button/#api] ## Radio.Button: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `value` | `string` | `undefined` | The string value the radio button is associated with. `selected` | `boolean` | `false` | Specify if the radio button is selected. `disabled` | `boolean` | `false` | Specify if the radio button is disabled. `class-selected` | `string` | `""` | Additional CSS classes to apply to the button when selected. `class-disabled` | `string` | `""` | Additional CSS classes to apply to the button when disabled. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio-button/#slots] ## Radio.Button: Slots (1/3) #### Radio.ButtonLabel Allows customization of the radio button’s label. This slot can be used to include additional elements in the label or place the label before the control of the radio button. ##### Properties Prop Name | Type | Default | Description `before` | `boolean` | `false` | Specify if the label should be put before the radio button control `children` | `JSX.Element` | `undefined` | Content to render inside the label, which can be any valid JSX element. ##### Usage ```tsx import Radio from '@components/Basic/RadioGroup/Radio'; import Block from '@components/Layout/Block/Block'; const App = () => { return ( Windowed Fullscreen Mode Borderless ); }; export default App; ``` **Caution:** If the `Label` slot is used then the other `children` of the `Radio.Button` component won’t be rendered. #### Radio.ButtonControl This slot allows you to customize the control of the `Radio.Button` component when it is not selected. Use it to apply custom styles, classes or include additional elements in the control of the radio button. ##### Properties --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio-button/#slots] ## Radio.Button: Slots (2/3) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the radio button control. `class` | `string` | `""` | Additional CSS classes to style the radio button control. `children` | `JSX.Element` | `undefined` | Content to render inside the radio button control, which can be any valid JSX element. ##### Usage ```tsx import Radio from '@components/Basic/RadioGroup/Radio'; import Block from '@components/Layout/Block/Block'; const App = () => { return ( Windowed Fullscreen Mode Borderless ); }; export default App; ``` #### Radio.ButtonIndicator This slot allows you to override the default indicator displayed when the radio button is selected. Use it to apply custom styles, classes or include additional elements in the indicator of the radio button. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the radio button indicator. `class` | `string` | `""` | Additional CSS classes to style the radio button indicator. `children` | `JSX.Element` | `undefined` | Content to render inside the radio button indicator, which can be any valid JSX element. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio-button/#slots] ## Radio.Button: Slots (3/3) ```tsx import Radio from '@components/Basic/RadioGroup/Radio'; import Block from '@components/Layout/Block/Block'; import Icon from '@assets/check-mark.svg?component-solid'; const App = () => { return ( Windowed Fullscreen Mode Borderless ); }; export default App; ``` **Note:** The `Radio.ButtonIndicator` slot is only rendered when used inside the `Radio.ButtonControl` slot. #### Guide You can find examples of how to work with the radio buttons in the Radio documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio/] ## Radio The `Radio` component lets you render a set of mutually-exclusive options in your UI, where only one choice can be selected at a time. Under the hood it uses Solid’s context API and it works in conjunction with the `Radio.Button` slot. For more information about the `Radio.Button` slot, check out the Radio.Button documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio/#installation] ## Radio: Installation Every component ships with the boilerplate. If you are working in your own project, add `RadioGroup` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add RadioGroup ``` The CLI pulls in whatever `RadioGroup` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio/#usage] ## Radio: Usage To create a radio options in your UI, you need to wrap the `Radio.Button` slots with the `Radio` component. **index.tsx:** ```tsx import Radio from '@components/Basic/RadioGroup/Radio'; <> red green blue ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio/#api] ## Radio: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `RadioRef \| undefined` | `undefined` | A reference to the component that gives you access to its methods and the underlying HTML element. Useful if you need to set the selected option programmatically. `disabled` | `boolean` | `false` | Specify if the radio is disabled. `class-disabled` | `string` | `""` | Additional CSS classes to apply to the component when disabled. `onChange` | `(selected: string) => void` | `undefined` | A function that is called every time the selected option changes. It can be used to retrieve the selected option’s value. `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the radio’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio/#ref-api] ## Radio: Ref API To interact with the `Radio` programmatically, you can use the `RadioRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the radio’s root HTML element, useful for DOM access or styling. `selected` | `Accessor` | The currently selected option. Use `selected()` to get the value. #### Methods Method | Parameters | Return Value | Description `changeOption` | `newOption: string` | `void` | Programmatically change the selected option. `changeSelected` | direction: `prev` \| `next` | `void` | Programmatically change the selected option to the previous or next one. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio/#implemented-navigation-actions] ## Radio: Implemented Navigation Actions The `Radio` component implements the following navigation actions by default: Action Name | Behavior `move-left` | Moves the selected option to the previous one `move-right` | Moves the selected option to the next one You can extend the `Radio` with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import Radio from '@components/Basic/RadioGroup/Radio'; console.log('Radio button confirmed!'), 'move-left': () => console.log('Custom previous logic') // overrides default move-left behavior }} > Option 1 Option 2 ``` Using an `anchor` element lets the `Radio` respond to navigation actions when another element is focused: ```tsx ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio/#guide] ## Radio: Guide (1/2) #### Retrieve the value of the selected option when it changes To retrieve the value of the selected option: - Use the `onChange` prop to respond when the selected option changes ##### Steps 1. Provide a callback to the `onChange` prop to respond to state changes. 2. Inside the callback, access the selected option’s value via the `selected` argument. ```tsx import Radio from '@components/Basic/RadioGroup/Radio'; const App = () => { const getValue = (selected: string) => { console.log(selected); } return ( <> red green blue ); }; export default App; ``` #### Set the selected option Programmatically The `Radio` component lets you set the selected option through code. ##### Steps 1. Declare a `ref` variable with type `RadioRef` and pass it to the `Radio` component. 2. Call `ref.changeOption()` from anywhere (e.g., a keyboard event or external button) to set a new selected option programmatically. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/radio/#guide] ## Radio: Guide (2/2) ```tsx import Radio, { RadioRef } from '@components/Basic/RadioGroup/Radio'; const App = () => { let RadioRef!: RadioRef; const handleKeyPress = (e: KeyboardEvent) => { if (e.keyCode !== 13) return RadioRef.changeOption('green'); } return ( <> red green blue ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/rounded-button/] ## RoundedButton The `RoundedButton` component is used to create rounded button elements in the UI with the help of the `Button` component. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/rounded-button/#installation] ## RoundedButton: Installation Every component ships with the boilerplate. If you are working in your own project, add `RoundedButton` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add RoundedButton ``` The CLI pulls in whatever `RoundedButton` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/rounded-button/#usage] ## RoundedButton: Usage The `RoundedButton` component accepts the same properties as the `Button` component so it can be configured in the same way. The main difference is that the `RoundedButton` component will render a button with rounded corners. **index.tsx:** ```tsx import RoundedButton from '@components/Basic/RoundedButton/RoundedButton'; <> Large button Button with middle size Small size button Small size button with no fitting the text ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/rounded-button/#api] ## RoundedButton: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLButtonElement \| undefined` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. The HTML element can be accessed directly by the ref object. `disabled` | `boolean` | `false` | Specify if the button is disabled `size` | `'large' \| 'middle' \| 'small'` | `''` | Specify the size of the button. If an empty string is passed, the button won’t have any size. In that case, please specify the size through the `class` or `style` properties. `textFit` | `boolean` | `true` | Specify if the text inside the button should be fitted. By default, this option is **enabled**. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the button. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the button’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/rounded-button/#guide] ## RoundedButton: Guide #### Custom corners radius If you need to apply a custom radius to the corners of the rounded button, you can do so by using the `style` property or applying a CSS `class` to the button. ```tsx import Button from '@components/Basic/RoundedButton/RoundedButton'; const App = () => { return ( Button ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment-button/] ## Segment.Button The `Segment.Button` slot represents a single option within a `Segment`. It renders a clickable button with a transition. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment-button/#installation] ## Segment.Button: Installation Every component ships with the boilerplate. If you are working in your own project, add `Segment` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Segment ``` The CLI pulls in whatever `Segment` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment-button/#usage] ## Segment.Button: Usage To create a `Segment.Button` you need to wrap it in the `Segment` component and provide a value to it. You must also provide the `selected` prop to the `Segment.Button` you wish to be selected by default. **index.tsx:** ```tsx import Segment from '@components/Basic/Segment/Segment'; <> red green blue ``` **Note:** If multiple `Segment.Button` components have the `selected` prop, only the last one with `selected` will be active by default. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment-button/#api] ## Segment.Button: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `value` | `string` | `undefined` | The string value the Segment button is associated with. `selected` | `boolean` | `false` | Specify if the Segment button is selected. `disabled` | `boolean` | `false` | Specify if the Segment button is disabled. `class-disabled` | `string` | `""` | Additional CSS classes to apply to the button when disabled. #### Guide You can find examples of how to work with the Segment buttons in the Segment documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment/] ## Segment The `Segment` component lets you render a set of mutually-exclusive options in your UI, where only one choice can be selected at a time. It functions the same way as the Radio component Under the hood it uses Solid’s context API and it works in conjunction with the `Segment.Button` slot. For more information about the `Segment.Button` slot, check out the Segment.Button documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment/#installation] ## Segment: Installation Every component ships with the boilerplate. If you are working in your own project, add `Segment` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Segment ``` The CLI pulls in whatever `Segment` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment/#usage] ## Segment: Usage To create a Segment options in your UI, you need to wrap the `Segment.Button` slots with the `Segment` component. **index.tsx:** ```tsx import Segment from '@components/Basic/Segment/Segment'; <> red green blue ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment/#api] ## Segment: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `SegmentRef \| undefined` | `undefined` | A reference to the component that gives you access to its methods and the underlying HTML element. Useful if you need to set the selected option programmatically. `disabled` | `boolean` | `false` | Specify if the Segment is disabled. `class-selected` | `string` | `""` | Additional CSS classes applied when the button option is selected. `class-disabled` | `string` | `""` | Additional CSS classes to apply to the component when disabled. `onChange` | `(selected: string) => void` | `undefined` | A function that is called every time the selected option changes. It can be used to retrieve the selected option’s value. `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the segment’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment/#ref-api] ## Segment: Ref API To interact with the `Segment` programmatically, you can use the `SegmentRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the segment’s root HTML element, useful for DOM access or styling. `selected` | `Accessor` | The currently selected option. Use `selected()` to get the value. #### Methods Method | Parameters | Return Value | Description `selectOption` | `newOption: string` | `void` | Programmatically change the selected option. `changeSelected` | direction: `prev` \| `next` | `void` | Programmatically change the selected option to the previous or next one. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment/#slots] ## Segment: Slots (1/2) #### Segment.Indicator Allows customization of the segment’s indicator element which is responsible for the transition when the selected option is switched. This slot can be used to customize the element’s appereance. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the segment indicator. `class` | `string` | `""` | Additional CSS classes to style the segment indicator. **Caution:** When you customize the styles of `Segment.Indicator`, you must also apply the same styles to the `::before` pseudo-element of `Segment.Button`.\ This is because, on initial render, the indicator is visually represented by the button’s `::before` element.\ If you only style the indicator, you may see inconsistent appearance until the first selection change. You can customize it like: ```css .indicator { background-color: green; } .segment-button::before { background-color: green !important; } ``` ##### Usage In the following example, we are going to change the background color of the indicator and apply a custom class. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment/#slots] ## Segment: Slots (2/2) ```tsx import Radio from '@components/Basic/RadioGroup/Radio'; const App = () => { return ( Easy Medium Hard Very Hard ;) ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment/#implemented-navigation-actions] ## Segment: Implemented Navigation Actions The `Segment` component implements the following navigation actions by default: Action Name | Behavior `move-left` | Moves the selected option to the previous one `move-right` | Moves the selected option to the next one You can extend the `Segment` with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import Segment from '@components/Basic/Segment/Segment'; console.log('Segment item confirmed!'), 'move-left': () => console.log('Custom previous logic') // overrides default move-left behavior }} > Option 1 Option 2 ``` Using an `anchor` element lets the `Segment` respond to navigation actions when another element is focused: ```tsx ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment/#guide] ## Segment: Guide (1/2) #### Retrieve the value of the selected option when it changes To retrieve the value of the selected option: - Use the `onChange` prop to respond when the selected option changes ##### Steps 1. Provide a callback to the `onChange` prop to respond to state changes. 2. Inside the callback, access the selected option’s value via the `selected` argument. ```tsx import Segment from '@components/Basic/Segment'; const App = () => { const getValue = (selected: string) => { console.log(selected); } return ( <> red green blue ); }; export default App; ``` #### Set the selected option programmatically The `Segment` component lets you set the selected option through code. ##### Steps 1. Declare a `ref` variable with type `SegmentRef` and pass it to the `Segment` component. 2. Call `ref.selectOption()` from anywhere (e.g., a keyboard event or external button) to set a new selected option programmatically. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/segment/#guide] ## Segment: Guide (2/2) ```tsx import Segment, { SegmentRef } from '@components/Basic/Segment'; const App = () => { let SegmentRef!: SegmentRef; const handleKeyPress = (e: KeyboardEvent) => { if (e.keyCode !== 13) return SegmentRef.selectOption('green'); } return ( <> red green blue ); }; export default App; ``` **Tip:** To dynamically render options, you can use an array and map over it: ```tsx const options = [ {value: 'option-1', text: 'Option 1', selected: true, disabled: false}, {value: 'option-2', text: 'Option 2', selected: false} ... ]; ... {options.map((option) => ( {option.text} ))} ``` Alternatively, you can use the SolidJS `For` component: ```tsx const options = [ {value: 'option-1', text: 'Option 1', selected: true, disabled: false}, {value: 'option-2', text: 'Option 2', selected: false} ... ]; ... {(option) => ( {option.text} )} ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/slider/] ## Slider The `Slider` component allows users to select a numeric value from a specified range by dragging a handle along a track. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/slider/#installation] ## Slider: Installation Every component ships with the boilerplate. If you are working in your own project, add `Slider` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Slider ``` The CLI pulls in whatever `Slider` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/slider/#usage] ## Slider: Usage To use the `Slider` component, specify the minimum (`min`), maximum (`max`), initial value (`value`), and step size (`step`). **index.tsx:** ```tsx import Slider from '@components/Basic/Slider/Slider'; <> ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/slider/#api] ## Slider: API (1/2) #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `SliderRef \| undefined` | `undefined` | A reference to the component that gives you access to its methods and the underlying HTML element. Useful if you need to set the value of the slider programmatically. `value` | `number` | `undefined` | The current value of the slider. Use this to control or set the slider’s position. The prop is reactive - updating it externally moves the handle. `min` | `number` | `undefined` | The minimum value that the slider can select. `max` | `number` | `undefined` | The maximum value that the slider can select. `step` | `number` | `undefined` | The amount by which the slider value changes when the handle is moved. Determines the granularity of the slider. `onChange` | `(value: number) => void` | `undefined` | A function that is called whenever the slider’s value changes. It only fires when the value actually changes, not on every mouse move. `onChangeEnd` | `(value: number) => void` | `undefined` | A function that is called when the user finishes interacting with the slider (e.g. on mouse release). Useful for committing the final value without reacting to every intermediate change. `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/slider/#api] ## Slider: API (2/2) Prop Name | Type | Default | Description `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the slider’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/slider/#ref-api] ## Slider: Ref API To interact with the `Slider` programmatically, you can use the `SliderRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the slider’s root HTML element, useful for DOM access or styling. `value` | `Accessor` | The current value of the slider. Use `value()` to get the latest value. #### Methods Method | Parameters | Return Value | Description `changeValue` | `newValue: number` | `void` | Programmatically sets a new value for the slider. `stepValue` | `direction: 1 \| -1` | `void` | Steps the value up (`1`) or down (`-1`) by the `step` amount. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/slider/#slots] ## Slider: Slots (1/4) #### Slider.Track Customizes the slider’s track. Use this slot to apply custom classes or styles to the track area of the slider. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the slider track. `class` | `string` | `""` | Additional CSS classes to style the slider track. ##### Usage ```tsx import Slider from '@components/Basic/Slider/Slider'; const App = () => { return ( <> ); }; export default App; ``` #### Slider.Fill Customizes the filled portion of the slider track that visually represents the current value. Use this slot to apply custom styles or classes to the fill area. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the slider fill. `class` | `string` | `""` | Additional CSS classes to style the slider fill. ##### Usage ```tsx import Slider from '@components/Basic/Slider/Slider'; const App = () => { return ( <> ); }; export default App; ``` #### Slider.Handle Customizes the draggable handle of the slider. Use this slot to apply custom styles or classes to the slider handle. ##### Properties --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/slider/#slots] ## Slider: Slots (2/4) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the slider handle. `class` | `string` | `""` | Additional CSS classes to style the slider handle. `styleActive` | `JSX.CSSProperties` | `{}` | Inline styles applied to the handle while it is active (the slider is focused via keyboard/gamepad navigation). Merged on top of `style`. `classActive` | `string` | `""` | CSS class applied to the handle while it is active, replacing the default active styling. ##### Usage ```tsx import Slider from '@components/Basic/Slider/Slider'; const App = () => { return ( <> ); }; export default App; ``` #### Slider.Thumb The `Slider.Thumb` slot renders a small rectangular element above the handle that displays the current value of the slider. Use this slot to customize the appearance or content of the value indicator. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the slider thumb (value indicator). `class` | `string` | `""` | Additional CSS classes to style the slider thumb. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/slider/#slots] ## Slider: Slots (3/4) ```tsx import Slider from '@components/Basic/Slider/Slider'; const App = () => { return ( <> ); }; export default App; ``` **Caution:** The thumb of the slider won’t be displayed by default. To enable it provide the `Thumb` slot inside the `Slider` component. #### Slider.Grid The `Slider.Grid` slot displays a visual indicator of progress along the slider’s range, dividing the track into evenly spaced segments called “pols.” Each pol marks a separation between the minimum and maximum values, helping users see how far the current value has moved. You can control the number of main pols (with value labels) using the `pols` prop.\ Additionally, by enabling the `pols-without-text` prop, smaller unlabeled pols are rendered between the main pols for finer granularity and enhanced visual feedback. ##### Properties --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/slider/#slots] ## Slider: Slots (4/4) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the grid container. `class` | `string` | `""` | Additional CSS classes to style the grid container. `pols` | `number` | `5` | Number of main pols (segments with value labels) to display along the slider track. `pols-without-text` | `number` | `5` | If prop is present, it renders smaller unlabeled pols between main pols for finer granularity. `pol-style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to each pol (segment marker). `pol-class` | `string` | `""` | Additional CSS classes to style each pol (segment marker). `pol-value-style` | `JSX.CSSProperties` | `{}` | Inline styles for poles displaying the slider’s current value. `pol-value-class` | `string` | `""` | Additional CSS classes for poles displaying the slider’s current value. ##### Usage ```tsx import Slider from '@components/Basic/Slider/Slider'; const App = () => { return ( <> ); }; export default App; ``` **Caution:** The `Slider.Grid` slot will only be rendered if you include it as a child of the `Slider` component. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/slider/#implemented-navigation-actions] ## Slider: Implemented Navigation Actions The `Slider` component implements the following navigation actions by default: Action Name | Behavior `move-left` | Decreases the slider value by the `step` amount `move-right` | Increases the slider value by the `step` amount You can extend the `Slider` with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import Slider from '@components/Basic/Slider/Slider'; console.log('Slider confirmed!'), 'back': () => console.log('Going back') }} /> ``` For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/slider/#guide] ## Slider: Guide (1/2) #### Retrieve and use the slider value - To get the current value of the `Slider` component, use the `onChange` prop. ##### Steps 1. Define a state variable (e.g., using `createSignal`) to store the slider value. 2. Pass a callback to the `onChange` prop that updates this state variable. 3. Use the state variable wherever you need the slider’s value. ```tsx import Slider from '@components/Basic/Slider/Slider'; import { createSignal} from 'solid-js'; const App = () => { const [sliderValue, setSliderValue] = createSignal(50); return ( <> setSliderValue(value)} value={50} max={100} min={0} step={1} />
{sliderValue()}
); }; export default App; ``` #### React only to the final value - The `onChange` prop fires every time the value changes while dragging. If you only care about the final value once the user finishes interacting (e.g. to avoid expensive work on every step), use the `onChangeEnd` prop instead. `onChangeEnd` is called when the user releases the handle after a drag, and after navigation actions (`move-left` / `move-right`) settle. ```tsx import Slider from '@components/Basic/Slider/Slider'; import { createSignal} from 'solid-js'; const App = () => { const [sliderValue, setSliderValue] = createSignal(50); return ( <> setSliderValue(value)} value={50} max={100} min={0} step={1} />
{sliderValue()}
); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/slider/#guide] ## Slider: Guide (2/2) #### Set the value of the slider programmatically The `Slider` component lets you set the `value` through code. ##### Steps 1. Declare a `ref` variable with type `SliderRef` and pass it to the `Slider` component. 2. Call `ref.changeValue()` from anywhere (e.g., a keyboard event or external button) to set the value programmatically. ```tsx import Slider { SliderRef } from '@components/Basic/Slider/Slider'; const App = () => { let sliderRef!: SliderRef; const handleKeyPress = (e: KeyboardEvent) => { if (e.keyCode !== 13) return sliderRef.changeValue(100); } return ( <> ); }; export default App; ``` #### Customizing grid pols You can customize the grid pols that display values using the `pol-value-style` and `pol-value-class` properties of the `Slider.Grid` slot. This is particularly useful for adjusting the font size, width, or text wrapping behavior of the pol value elements. By default, the text wraps to break words based on the width of the pol value element. In the following example, you can see how to modify the font size, width, and disable the `overflow-wrap` property for the pol value elements. ```tsx import Slider from '@components/Basic/Slider/Slider'; const App = () => { return ( ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/state/] ## State The `State` component allows you to define multiple UI states, with only one being rendered at a time based on the active state. This component can be used for various purposes: - Simulating a router - Define different UI states that render based on the selected state. You can create UI elements to control the active state, and when the control changes, the `State` component updates the UI accordingly. - Creating different states for a component - For example, you can create different crosshairs for different weapons in a game. A pistol can have a smaller crosshair, while a bazooka can have a larger one. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/state/#installation] ## State: Installation Every component ships with the boilerplate. If you are working in your own project, add `State` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add State ``` The CLI pulls in whatever `State` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/state/#usage] ## State: Usage The `State` component must wrap different states as child elements using the `Match` component. You can set the default state when the UI loads using the `default` attribute of the `State` component. Each `Match` component should wrap a different state of the UI, and you need to set the `name` attribute of the `Match` component to define the name of that state. Setting `name` to `''` will be used as a fallback state if no other defined state matches during a state change. ```tsx import State, { Match } from '@components/Basic/State/State'; const App = () => { return ( Fallback State 1 State 2 ); }; export default App; ``` In this case, the `State 1` text will be rendered as the `State` component will match `state-1` as the default state. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/state/#api] ## State: API (1/2) #### State Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `StateComponentRef` | `undefined` | Retrieves the state’s properties and methods, assigning them to a local variable. `name` | `string` | `undefined` | The identifier for the state component. This name can be used to access the state component’s methods later through the `states` object. `default` | `string` | `undefined` | The default state to be rendered initially. `onBeforeStateChange` | `(currentState?: string, nextState?: string, currentStateElement?: JSX.Element) => {}` | `undefined` | Callback invoked right before the state changes. It receives the current and next state names and the `HTML` element of the current state before the change. `onStateChanged` | `(currentState?: string, prevState?:string, currentStateElement?: JSX.Element) => {}` | `undefined` | Callback invoked after the state changes. It receives the current and previous state names and the `HTML` element of the current state after the change. #### Match Props Prop Name | Type | Default | Description `name` | `string` | `Required` | Specifies the name of the state to be matched. #### State Methods You can access the state methods via the `ref` of the `State` component or through the `states` object. You can see more in the guide about how to use them. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/state/#api] ## State: API (2/2) Method | Parameters | Return Value | Description `changeState` | `value`: string \| ((prevState: string) => string) | `void` | Changes the state of the `State` component. You can pass a string value directly or a function that has the previous state as argument and returns the new state as a string. `currentState` | None | `string` | Returns the current state as a string. To get the current state, call `ref.currentState()`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/state/#guide] ## State: Guide (1/4) #### Dynamically update the state through ref To dynamically update the state of the `State` component, you need to use a ref of type `StateComponentRef`. Once you have the ref, you can use the `changeState` method to switch the active state. ```tsx import State, { Match, StateComponentRef } from '@components/Basic/State/State'; const App = () => { let ref: StateComponentRef; const changeStateToTwo = () => { ref.changeState('state-2'); }; const changeStateToOne = () => { // Use a callback to access the previous state if needed ref.changeState((prevState) => prevState !== 'state-2' ? prevState : 'state-1'); }; return (
State 1
State 2
); }; export default App; ``` In this example, the `default` attribute is set on the `State` component, so `State 1` is rendered initially. The `changeState` method from the `ref` object is used to change the state. The first method demonstrates changing the state by passing the next state as a string, while the second method shows how to access the previous state before changing to the next state. #### Dynamically update state using the states object --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/state/#guide] ## State: Guide (2/4) The `State` component exports a `states` object that holds information for all `State` components in the UI. Only `State` components with a specified `name` attribute are included in this collection. If the `name` attribute is omitted, the component won’t be added to the collection. Accessing methods for a `State` component is easier using the `states` object compared to using `ref`. Import the `states` collection from the `State` component and access specific state methods like this: `states['state-name'].changeState`. Here’s an example of dynamically changing states via the `states` object: ```tsx import State, { Match, states } from '@components/Basic/State/State'; const App = () => { const changeStateToTwo = () => { states['two-states'].changeState('state-2'); }; const changeStateToOne = () => { states['two-states'].changeState((prevState) => prevState !== 'state-2' ? prevState : 'state-1'); }; return (
State 1
State 2
); }; export default App; ``` Using the `states` object, you can avoid setting the `ref` on the `State` component. Instead, set the `name` attribute to access its methods through the `states` object. Depending on your use case and preferences, you can use both `ref` and the `states` object to access `State` component methods. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/state/#guide] ## State: Guide (3/4) The advantage of the `states` object over `ref` is that it can be imported and used throughout your project, whereas the usability of the `ref` object is limited to the file where it is set. #### Handling State Changes To perform actions before or after the state changes, you can use the `onBeforeStateChange` and `onStateChanged` props of the `State` component. These methods accept arguments such as the current, previous, and next states, as well as the HTML element of the current state, which is the element wrapped inside the `Match` component for the current state. Here’s an enhanced example demonstrating how to use these handlers to log state changes: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/state/#guide] ## State: Guide (4/4) ```tsx import State, { Match, StateComponentRef } from '@components/Basic/State/State'; const App = () => { let ref: StateComponentRef; const changeStateToTwo = () => { ref.changeState('state-2'); }; const changeStateToOne = () => { ref.changeState((prevState) => prevState !== 'state-2' ? prevState : 'state-1'); }; const onBeforeStateChange = (currentState?: string, nextState?: string) => console.log(`Changing from ${currentState} to ${nextState}`); const onStateChanged = (currentState?: string, prevState?: string) => console.log(`Changed from ${prevState} to ${currentState}`); return (
State 1
State 2
); }; export default App; ``` With this setup, when you change the state by clicking on the `State 1` or `State 2` elements, you will see log messages such as: ```log Changing from state-1 to state-2 Changed from state-1 to state-2 ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/state/#expected-behaviors] ## State: Expected Behaviors The `State` component does not support dynamically generated `Match` elements at runtime. All states must be predefined, and adding or removing states dynamically will result in undefined behavior. Here is an incorrect example that demonstrates adding new `Match` components to the `State` component at runtime: ```tsx const App = () => { const [states, updateStates] = createSignal(['1', '2', '3']); setInterval(() => { const stateName = parseInt(Math.random() * 1000) + ''; updateStates((prev) => { prev.push(stateName); return prev; }); stateRef.changeState(states()[stateName]); }, 1000); return ( Fallback {states().map((state: string) => ( {state} ))} ); }; ``` In this example, a new state is added every 1000 milliseconds, and the `State` component attempts to switch to it. This dynamic addition of `Match` components will lead to undefined behavior and is not recommended. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/state/#example] ## State: Example Here’s a minimal example demonstrating the usage of the `State` component to create a simple router with tabs and a ‘router view’. The ‘router view’ is managed by the `State` component. ```tsx import State, { Match, states } from '@components/Basic/State/State'; const App = () => { const tabs = ['page 1', 'page 2', 'page 3']; const changePage = (event: any) => { const tabName = event.currentTarget.dataset.tab; states['menu'].changeState(tabName); }; return (
{tabs.map((tab) => (
{tab}
))}
Fallback This is Page 1 This is Page 2 This is Page 3
); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper-items/] ## Stepper.Items The `Stepper.Items` slot acts as a container for all the `Stepper.Item` components within the `Stepper`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper-items/#installation] ## Stepper.Items: Installation Every component ships with the boilerplate. If you are working in your own project, add `Stepper` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Stepper ``` The CLI pulls in whatever `Stepper` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper-items/#usage] ## Stepper.Items: Usage To use `Stepper.Items`, place it inside the `Stepper` component as shown below: **index.tsx:** ```tsx import Stepper from '@components/Basic/Stepper/Stepper'; red green blue ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper-items/#api] ## Stepper.Items: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied directly to the container element of the stepper items. `class` | `string` | `""` | Additional CSS classes for the container element of the stepper items. `children` | `JSX.Element` | `""` | The children of `Stepper.Items` should include all `Stepper.Item` components. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper-items/#guide---customize-the-containers-appearance] ## Stepper.Items: Guide - Customize the container’s appearance To modify the width of the container displaying the selected item, you can use the following approach: ```tsx import Stepper from '@components/Basic/Stepper/Stepper'; const App = () => { return ( red green blue ); }; export default App; ``` **Note:** Ensure you set `flex: 'none'` because the default container uses `flex: 1 0 0`, which automatically adjusts its size based on the stepper’s width. Without disabling this behavior, the `width` property in the `style` prop will not take effect! **Tip:** You can adjust the width of the items container to accommodate items with longer text that might otherwise overflow. Alternatively, you can modify the width of the entire Stepper component to achieve a similar effect. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper-items/#slots] ## Stepper.Items: Slots (1/2) #### Stepper.Item This slot is used to add individual items to the Stepper and customize their appearance. **Note:** The `Stepper.Item` must always be placed within the `Stepper.Items` slot. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied directly to the stepper item element. `class` | `string` | `""` | Additional CSS classes for the stepper item element. `value` | `string` | `undefined` | The value associated with the stepper item. `selected` | `boolean` | `false` | Specifies whether the stepper item is selected. `children` | `JSX.Element` | `""` | Content of the item, which can include text, HTML, or JSX elements. ##### Usage ```tsx import Stepper from '@components/Basic/Stepper/Stepper'; const App = () => { return ( red green blue ); }; export default App; ``` **Note:** You can include multiple `Stepper.Item` components within the `Stepper.Items` slot as needed. **Note:** Only one `Stepper.Item` can be selected at a time. If multiple `Stepper.Item` components have the `selected` prop enabled, the last one will be selected on initial load. **Tip:** To dynamically generate items, you can use an array and map over it: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper-items/#slots] ## Stepper.Items: Slots (2/2) ```tsx const options = [ {value: 'option-1', text: 'Option 1', selected: true, disabled: false}, {value: 'option-2', text: 'Option 2', selected: false} ... ]; ... {options.map((option) => ( {option.text} ))} ``` Alternatively, you can use the SolidJS `For` component: ```tsx const options = [ {value: 'option-1', text: 'Option 1', selected: true, disabled: false}, {value: 'option-2', text: 'Option 2', selected: false} ... ]; ... {(option) => ( {option.text} )} ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper/] ## Stepper The `Stepper` component enables users to navigate through a set of options. It integrates seamlessly with the `Stepper.Items` and `Stepper.Item` slots. For more details about `Stepper.Items` and `Stepper.Item`, refer to the Stepper.Items documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper/#installation] ## Stepper: Installation Every component ships with the boilerplate. If you are working in your own project, add `Stepper` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Stepper ``` The CLI pulls in whatever `Stepper` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper/#usage] ## Stepper: Usage To include a stepper in your UI, wrap the `Stepper.Items` and `Stepper.Item` slots within the `Stepper` component: **index.tsx:** ```tsx import Stepper from '@components/Basic/Stepper/Stepper'; red green blue ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper/#api] ## Stepper: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `StepperRef \| undefined` | `undefined` | A reference to the component, providing access to its methods and underlying HTML element for programmatic control. `disabled` | `boolean` | `false` | Disables the stepper when set to `true`. `class-disabled` | `string` | `""` | Additional CSS classes to apply when the stepper is disabled. `controls-position` | `'before' \| 'after'` | `''` | Determines the position of the control arrows. If not set, the selected option appears between the arrows. If set to `'before'`, the arrows appear before the selected option; if `'after'`, they appear after it. `loop` | `boolean` | `false` | Enables looping through options when navigating past the first or last option using the controls. `onChange` | `(value: string) => void` | `undefined` | Callback function triggered whenever the selected option changes, providing the selected option’s value. `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the stepper’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper/#ref-api] ## Stepper: Ref API To interact with the `Stepper` programmatically, you can use the `StepperRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the stepper’s root HTML element, useful for DOM access or styling. `selected` | `Accessor` | The currently selected option. Use `selected()` to get the value. `options` | `string[]` | The available options for the stepper. #### Methods Method | Parameters | Return Value | Description `setOption` | `newOption: string` | `void` | Programmatically change the selected option. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper/#slots] ## Stepper: Slots (1/3) #### Stepper.Control The `Stepper.Control` slot lets you customize the buttons used to change the selected option in the stepper. By default, the control consists of two arrow buttons for navigating to the previous or next option. **Note:** The right arrow is a rotated version of the left arrow (rotated 180 degrees). Keep this in mind when implementing a custom control. You only need to define the left arrow in the slot, as the right arrow will automatically be a rotated duplicate. You can apply additional CSS classes and styles to modify the appearance of the default arrows. If you want to replace the default arrows with a custom control, you can provide `children` using any valid JSX syntax. When custom content is provided, the default arrows are replaced, and the `style` and `class` props for the slot will no longer apply. Instead, you should style your custom control within the `children` content. The click functionality for navigation is automatically handled, so you only need to focus on the visual design of the control. **Note:** If the `loop` option is not enabled on the `Stepper` component, the controls will be hidden/disabled when the first or last option is selected. Specifically, the left arrow will be hidden/disabled when the first option is selected, and the right arrow will behave similarly for the last option. ##### Properties --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper/#slots] ## Stepper: Slots (2/3) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply to the default arrow elements. `class` | `string` | `""` | Additional CSS classes for the default arrow elements. `children` | `JSX.Element` | `""` | Custom content to replace the default arrow controls. `hidden-class` | `string` | `""` | CSS class to override the default behavior when the control is hidden. If `loop` is not enabled, the left control will be hidden/disabled when the first option is selected, and the right control will behave similarly for the last option. ##### Usage ```css .control-hidden { pointer-events: none; opacity: 0.1; } ``` **Tip:** To completely hide the control when no other options are available, you can use `display: none`: ```css .control-hidden { display: none; } ``` ```tsx import Stepper from '@components/Basic/Stepper/Stepper'; const App = () => { return ( red green blue ); }; export default App; ``` ##### Usage with custom control --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper/#slots] ## Stepper: Slots (3/3) ```tsx import Stepper from '@components/Basic/Stepper/Stepper'; import MyCustomArrow from '@assets/my-custom-arrow.svg?component-solid'; const App = () => { return ( red green blue ); }; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper/#implemented-navigation-actions] ## Stepper: Implemented Navigation Actions The Stepper component implements the following navigation actions by default: Action Name | Behavior `move-left` | Moves to the previous option in the stepper `move-right` | Moves to the next option in the stepper You can extend the Stepper with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import Stepper from '@components/Basic/Stepper/Stepper'; console.log('Current option selected!'), 'back': () => console.log('Going back from stepper') }} > red green blue ``` For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper/#guide] ## Stepper: Guide (1/2) #### Retrieve the selected option’s value on change To capture the value of the selected option: - Use the `onChange` prop to handle changes in the selected option. ##### Steps 1. Pass a callback function to the `onChange` prop to handle state updates. 2. Access the selected option’s value through the `selected` parameter in the callback. ```tsx import Stepper from '@components/Basic/Stepper/Stepper'; const App = () => { const handleSelectionChange = (selected: string) => { console.log(selected); }; return ( red green blue ); }; export default App; ``` #### Programmatically set the selected option The `Stepper` component allows you to programmatically update the selected option. ##### Steps 1. Create a `ref` variable of type `StepperRef` and assign it to the `Stepper` component. 2. Use the `ref.setOption()` method to programmatically set a new selected option, such as in response to a button click or keyboard event. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/stepper/#guide] ## Stepper: Guide (2/2) ```tsx import Stepper, { StepperRef } from '@components/Basic/Stepper/Stepper'; const App = () => { let stepperRef!: StepperRef; const handleKeyPress = (e: KeyboardEvent) => { if (e.keyCode !== 13) return stepperRef.setOption('green'); }; return ( red green blue ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-block/] ## TextBlock The `TextBlock` component is used to render text. Internally, it simply outputs an HTML `p` element containing the text. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-block/#installation] ## TextBlock: Installation Every component ships with the boilerplate. If you are working in your own project, add `TextBlock` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add TextBlock ``` The CLI pulls in whatever `TextBlock` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-block/#usage] ## TextBlock: Usage Using the `TextBlock` component is simple. After importing it, you can add text as a child element. **index.tsx:** ```tsx import TextBlock from '@components/Basic/TextBlock/TextBlock'; <> Text content. ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-block/#api] ## TextBlock: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Styles applied directly to the root element of the component.. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `HTMLButtonElement \| undefined` | `undefined` | Obtains the component’s DOM element and assigns it to a variable, allowing direct access to the HTML element via the ref object. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-block/#guide] ## TextBlock: Guide #### Accessing the HTML element To access the HTML element of the component and make modifications, you can add a `ref` property to the text block. ```tsx import TextBlock from '@components/Basic/TextBlock/TextBlock'; const App = () => { let ref: HTMLParagraphElement; return ( Text content. ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-input/] ## TextInput The `TextInput` component provides a highly customizable input field for handling text data. It supports various slots for injecting UI elements before or after the input, as well as customizing the input and placeholder behavior directly. The component automatically manages user input and provides utility methods to programmatically update or clear the value. This makes it suitable for use in both simple and complex form UIs. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-input/#installation] ## TextInput: Installation Every component ships with the boilerplate. If you are working in your own project, add `TextInput` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add TextInput ``` The CLI pulls in whatever `TextInput` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-input/#usage] ## TextInput: Usage To use the `TextInput` component, simply import it and pass any required props. **index.tsx:** ```tsx import TextInput from '@components/Basic/Input/TextInput/TextInput'; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-input/#api] ## TextInput: API (1/2) #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `TextInputRef \| undefined` | `undefined` | A reference to the component that gives you access to its methods and the underlying HTML element. Useful if you need to set the value of the input programmatically. `value` | `string` | `""` | The value of the input. Updating this prop is reflected in the input, allowing it to be controlled. Also sets the initial value. `disabled` | `boolean` | `false` | Disables the input if set to true. `readonly` | `boolean` | `false` | Specifies if the input is only able to be read. If set to true, the input will not accept values. `max-symbols` | `number` | `undefined` | Maximum number of symbols the input can accept. `class-disabled` | `string` | `undefined` | Optional class to apply when the input is disabled. `onChange` | `(value: string) => void` | `undefined` | A function that is called every time the input’s value has changed. It can be used to retrieve the up to date value of the input. `delay` | `number \| boolean` | `undefined` | When set, debounces the `onChange` callback by the given amount in milliseconds — it fires once typing pauses for that duration instead of on every keystroke. If set to `true`, the default delay of `250ms` is used. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-input/#api] ## TextInput: API (2/2) Prop Name | Type | Default | Description `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the input’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-input/#ref-api] ## TextInput: Ref API To interact with the `TextInput` programmatically, you can use the `TextInputRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the input’s root HTML element, useful for DOM access or styling. `input` | `HTMLInputElement` | A reference to the internal input element. `value` | `Accessor` | The current value of the input. Use `value()` to get the latest value. #### Methods Method | Parameters | Return Value | Description `changeValue` | `newValue: string` | `void` | Programmatically sets a new value in the input field. `clear` | None | `void` | Clears the current value of the input. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-input/#slots] ## TextInput: Slots (1/3) #### TextInput.Before Allows the injection of content before the input element — useful for icons, labels, or additional UI elements. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the before slot container. `class` | `string` | `""` | Additional CSS classes to style the before slot container. `children` | `JSX.Element` | `""` | Content to be rendered inside the before slot. This can be used to add custom elements or styles. ##### Usage ```tsx import TextInput from '@components/Basic/TextInput/TextInput'; import MagnifierIcon from @assets/icon.svg?component-solid; const App = () => { return ( ); }; export default App; ``` #### TextInput.After Allows the injection of content after the input element — ideal for suffixes, icons, or clear buttons. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the after slot container. `class` | `string` | `""` | Additional CSS classes to style the after slot container. `children` | `JSX.Element` | `""` | Content to be rendered inside the after slot. This can be used to add custom elements or styles. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-input/#slots] ## TextInput: Slots (2/3) ```tsx import TextInput from '@components/Basic/TextInput/TextInput'; import BinIcon from @assets/icon.svg?component-solid; const App = () => { return ( ); }; export default App; ``` #### TextInput.Input Used to override or extend the internal input element. This gives you full control over the input’s look and behavior. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the input element. `class` | `string` | `""` | Additional CSS classes to style the input element. ##### Usage ```tsx import TextInput from '@components/Basic/TextInput/TextInput'; const App = () => { return ( ); }; export default App; ``` #### TextInput.Placeholder Use this to define a placeholder content which will be displayed when the input has no value. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the input element. `class` | `string` | `""` | Additional CSS classes to style the input element. `children` | `JSX.Element` | `""` | Content to be rendered inside the placeholder slot. This can be used to add content as the input’s placeholder. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-input/#slots] ## TextInput: Slots (3/3) ```tsx import TextInput from '@components/Basic/TextInput/TextInput'; const App = () => { return ( Enter nickname ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-input/#implemented-navigation-actions] ## TextInput: Implemented Navigation Actions The `TextInput` component implements the following navigation actions by default: Action Name | Behavior `select` | Focuses the input element, making it ready for typing `back` | Blurs the input element, exiting typing mode You can extend the `TextInput` with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import TextInput from '@components/Basic/TextInput/TextInput'; console.log('Custom select action!'), 'move-up': () => console.log('Move up pressed') }} /> ``` For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-input/#guide] ## TextInput: Guide (1/2) #### Retrieve the input value - To get the current value of the `TextInput` component, use the `onChange` prop. - You can store the value in a state variable for use elsewhere. ##### Steps 1. Define a state variable (e.g., using `createSignal`) to store the input value. 2. Pass a callback to the `onChange` prop that updates this state variable. 3. Use the state variable wherever you need the input’s value. ```tsx import TextInput from '@components/Basic/TextInput/TextInput'; import { createSignal } from 'solid-js'; const App = () => { const [inputValue, setInputValue] = createSignal(""); return ( <> setInputValue(value)} />
{inputValue()}
); }; export default App; ``` #### Retrieve the input value with ref Alternatively, you can access the input’s value directly via a `ref`, avoiding the need to manage a state variable. ##### Steps 1. Declare a `ref` variable with type `TextInputRef` and pass it to the `TextInput` component. 2. Use `ref.value()` whenever you need the input’s current value. ```tsx import TextInput from '@components/Basic/TextInput/TextInput'; import { TextInputRef } from '@components/Basic/Input/shared/types'; import { createSignal } from 'solid-js'; const App = () => { let inputRef: TextInputRef; const logValue = () => { console.log(inputRef!.value()) } return ( <> ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-input/#guide] ## TextInput: Guide (2/2) #### Set the value of the input programmatically The `TextInput` component allows you to set the value programmatically through its `ref`. ##### Steps 1. Declare a `ref` variable with type `TextInputRef` and pass it to the `TextInput` component. 2. Call `ref.changeValue()` from anywhere (e.g., a keyboard event or external button) to set the value programmatically. 3. Optionally, you can clear the value of the input by calling `ref.clear()`. ```tsx import TextInput from '@components/Basic/TextInput/TextInput'; import { TextInputRef } from '@components/Basic/Input/shared/types'; import { createSignal } from 'solid-js'; const App = () => { let inputRef!: TextInputRef; const fillInput = (value: string) => { sliderRef.changeValue(value); } const clearInput = () => { sliderRef.clear(); } return ( <> ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-slider/] ## TextSlider The `TextSlider` component enables users to select a string value from a predefined set of options by dragging a handle along a track. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-slider/#installation] ## TextSlider: Installation Every component ships with the boilerplate. If you are working in your own project, add `TextSlider` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add TextSlider ``` The CLI pulls in whatever `TextSlider` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-slider/#usage] ## TextSlider: Usage To use the `TextSlider` component, specify the selectable options using the `values` prop. **index.tsx:** ```tsx import TextSlider from '@components/Basic/TextSlider/TextSlider'; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-slider/#api] ## TextSlider: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `TextSliderRef \| undefined` | `undefined` | A reference to the component, providing access to its methods and the underlying HTML element. Useful for programmatically setting the slider’s value. `value` | `string` | `undefined` | The current value of the slider. Use this to control or set the slider’s position. The prop is reactive - updating it externally moves the handle. `values` | `string[]` | `undefined` | An array of options that can be selected by dragging the slider’s handle. `onChange` | `(value: string) => void` | `undefined` | A callback function triggered whenever the slider’s value changes. It provides the updated value of the slider. `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the slider’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-slider/#ref-api] ## TextSlider: Ref API To interact with the `TextSlider` programmatically, you can use the `TextSliderRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the text slider’s root HTML element, useful for DOM access or styling. `value` | `Accessor` | The current value of the slider. Use `value()` to get the latest value. `values` | `Accessor` | The available options for the text slider. #### Methods Method | Parameters | Return Value | Description `changeValue` | `newValue: string` | `void` | Programmatically sets a new value for the text slider. `stepValue` | `direction: 1 \| -1` | `string` | Steps to the next (`1`) or previous (`-1`) value in the values array. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-slider/#slots] ## TextSlider: Slots (1/3) #### TextSlider.Track This slot allows customization of the slider’s track. Use it to apply custom styles or classes to the track area. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles for the slider track. `class` | `string` | `""` | Additional CSS classes for the slider track. ##### Usage ```tsx import TextSlider from '@components/Basic/TextSlider/TextSlider'; const App = () => { return ( ); }; export default App; ``` #### TextSlider.Fill This slot customizes the filled portion of the slider track, which visually represents the current value. Use it to apply custom styles or classes to the fill area. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles for the slider fill. `class` | `string` | `""` | Additional CSS classes for the slider fill. ##### Usage ```tsx import TextSlider from '@components/Basic/TextSlider/TextSlider'; const App = () => { return ( ); }; export default App; ``` #### TextSlider.Handle This slot customizes the draggable handle of the slider. Use it to apply custom styles or classes to the handle. ##### Properties --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-slider/#slots] ## TextSlider: Slots (2/3) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles for the slider handle. `class` | `string` | `""` | Additional CSS classes for the slider handle. `styleActive` | `JSX.CSSProperties` | `{}` | Inline styles applied to the handle while it is active (the slider is focused via keyboard/gamepad navigation). Merged on top of `style`. `classActive` | `string` | `""` | CSS class applied to the handle while it is active, replacing the default active styling. ##### Usage ```tsx import TextSlider from '@components/Basic/TextSlider/TextSlider'; const App = () => { return ( ); }; export default App; ``` #### TextSlider.Thumb The `TextSlider.Thumb` slot displays a small rectangular element positioned above the slider’s handle, showing the current value of the slider. You can use this slot to customize the appearance or content of the value indicator. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply to the slider thumb. `class` | `string` | `""` | Additional CSS classes for styling the slider thumb. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-slider/#slots] ## TextSlider: Slots (3/3) ```tsx import TextSlider from '@components/Basic/TextSlider/TextSlider'; const App = () => { return ( ); }; export default App; ``` **Caution:** The slider thumb is not displayed by default. To enable it, include the `Thumb` slot within the `TextSlider` component. #### TextSlider.Pol The `TextSlider.Pol` slot allows you to customize the appearance of the poles that represent the slider’s selectable values in a grid layout. You can style both the poles and the text displayed on them. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles for the poles. Use this to customize their appearance. `class` | `string` | `""` | Additional CSS classes for the poles. `text-style` | `JSX.CSSProperties` | `{}` | Inline styles for the text displayed on the poles. `text-class` | `string` | `""` | Additional CSS classes for the text displayed on the poles. ##### Usage ```tsx import TextSlider from '@components/Basic/TextSlider/TextSlider'; const App = () => { return ( ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-slider/#implemented-navigation-actions] ## TextSlider: Implemented Navigation Actions The `TextSlider` component implements the following navigation actions by default: Action Name | Behavior `move-left` | Moves to the previous value in the values array `move-right` | Moves to the next value in the values array You can extend the `TextSlider` with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import TextSlider from '@components/Basic/TextSlider/TextSlider'; console.log('Value selected!'), 'back': () => console.log('Going back') }} /> ``` For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/text-slider/#guide] ## TextSlider: Guide #### Retrieve and use the text slider value - To get the current value of the `TextSlider` component, use the `onChange` prop. ##### Steps 1. Define a state variable (e.g., using `createSignal`) to store the slider value. 2. Pass a callback to the `onChange` prop that updates this state variable. 3. Use the state variable wherever you need the slider’s value. ```tsx import TextSlider from '@components/Basic/TextSlider/TextSlider'; import { createSignal} from 'solid-js'; const App = () => { const [sliderValue, setSliderValue] = createSignal('Medium'); return ( <> setSliderValue(value)} values={['Easy', 'Medium', 'Hard']} />
{sliderValue()}
); }; export default App; ``` #### Set the value of the text slider programmatically The `TextSlider` component lets you set the `value` through code. ##### Steps 1. Declare a `ref` variable with type `TextSliderRef` and pass it to the `TextSlider` component. 2. Call `ref.changeValue()` from anywhere (e.g., a keyboard event or external button) to set the value programmatically. ```tsx import TextSlider { TextSliderRef } from '@components/Basic/TextSlider/TextSlider'; const App = () => { let textSliderRef!: SliderRef; const handleKeyPress = (e: KeyboardEvent) => { if (e.keyCode !== 13) return textSliderRef.changeValue('Easy'); } return ( ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/toggle-button/] ## ToggleButton The `ToggleButton` component is a versatile UI element that allows users to toggle between two states, such as “on” and “off.” --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/toggle-button/#installation] ## ToggleButton: Installation Every component ships with the boilerplate. If you are working in your own project, add `ToggleButton` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add ToggleButton ``` The CLI pulls in whatever `ToggleButton` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/toggle-button/#usage] ## ToggleButton: Usage To use the `ToggleButton` component, you can customize its labels and behavior as shown below: **index.tsx:** ```tsx import ToggleButton from '@components/Basic/ToggleButton/ToggleButton'; Off On ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/toggle-button/#api] ## ToggleButton: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the root element of the component. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `ToggleButtonRef \| undefined` | `undefined` | A reference to the component, providing access to its methods and underlying HTML element. `disabled` | `boolean` | `false` | Disables the toggle button, preventing user interaction. `class-checked` | `string` | `""` | Additional CSS classes applied when the toggle button is checked. `class-disabled` | `string` | `""` | Additional CSS classes applied when the toggle button is disabled. `checked` | `boolean` | `false` | Specifies the initial checked state of the toggle button. `onChange` | `(checked: boolean) => void` | `undefined` | Callback function triggered whenever the toggle button is toggled, providing the current checked state. `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the toggle button’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/toggle-button/#ref-api] ## ToggleButton: Ref API To interact with the `ToggleButton` programmatically, you can use the `ToggleButtonRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `checked` | `Accessor` | Read the current state: `ref.checked()` returns `true/false`. `element` | `HTMLDivElement` | A reference to the button’s underlying HTML element, useful for accessing DOM properties or applying additional styles. #### Methods Method | Parameters | Return Value | Description `setChecked` | `Setter` | `void` | Programmatically sets the checked state of the toggle button based on the provided boolean value. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/toggle-button/#slots] ## ToggleButton: Slots (1/4) #### ToggleButton.LabelLeft This slot enables customization of the left label of the toggle button. You can use it to include additional elements or modify the content of the left label. ##### Properties Prop Name | Type | Default | Description `children` | `JSX.Element` | `undefined` | The content to display inside the left label, which can be any valid JSX element. ##### Example ```tsx import ToggleButton from '@components/Basic/ToggleButton/ToggleButton'; const App = () => { return ( Off ); }; export default App; ``` #### ToggleButton.LabelRight This slot enables customization of the right label of the toggle button. You can use it to include additional elements or modify the content of the right label. ##### Properties Prop Name | Type | Default | Description `children` | `JSX.Element` | `undefined` | The content to display inside the right label, which can be any valid JSX element. ##### Example ```tsx import ToggleButton from '@components/Basic/ToggleButton/ToggleButton'; const App = () => { return ( On ); }; export default App; ``` #### ToggleButton.Control This slot allows you to customize the appearance and behavior of the `ToggleButton` control when it is in its unchecked state. You can use it to apply custom styles, add CSS classes, or include additional elements within the control. ##### Properties --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/toggle-button/#slots] ## ToggleButton: Slots (2/4) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the control element. `class` | `string` | `""` | Additional CSS classes to style the control element. `children` | `JSX.Element` | `undefined` | Content to render inside the control, which can be any valid JSX element. ##### Example ```tsx import ToggleButton from '@components/Basic/ToggleButton/ToggleButton'; const App = () => { return ( Off On ); }; export default App; ``` #### ToggleButton.Indicator This slot allows you to customize the indicator displayed when the toggle button is toggled. It can be styled or replaced with custom elements to suit your design needs. **Note:** The `ToggleButton.Indicator` slot must be used within the `ToggleButton.Control` slot. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the indicator element. `class` | `string` | `""` | Additional CSS classes to style the indicator element. `children` | `JSX.Element` | `undefined` | Content to render inside the indicator, which can be any valid JSX element. ##### Example --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/toggle-button/#slots] ## ToggleButton: Slots (3/4) ```tsx import ToggleButton from '@components/Basic/ToggleButton/ToggleButton'; const App = () => { return ( Off On ); }; export default App; ``` #### ToggleButton.Handle This slot allows you to customize the handle of the `ToggleButton` component. You can use it to apply custom styles, add CSS classes, or include additional elements. **Note:** The `ToggleButton.Handle` slot must be used within the `ToggleButton.Control` slot. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the handle element. `style-checked` | `JSX.CSSProperties` | `{}` | Inline styles to apply when the toggle button is in the checked state. `class` | `string` | `""` | Additional CSS classes to style the handle element. `class-checked` | `string` | `""` | Additional CSS classes to style the handle when the toggle button is checked. `children` | `JSX.Element` | `undefined` | Content to render inside the handle, which can be any valid JSX element. **Note:** The `style` and `class` properties are applied when the toggle button is unchecked, while `style-checked` and `class-checked` are applied when it is checked. ##### Example --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/toggle-button/#slots] ## ToggleButton: Slots (4/4) ```tsx import ToggleButton from '@components/Basic/ToggleButton/ToggleButton'; const App = () => { return ( Off On ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/toggle-button/#implemented-navigation-actions] ## ToggleButton: Implemented Navigation Actions The `ToggleButton` component implements the following navigation actions by default: Action Name | Behavior `select` | Toggles the button on/off You can extend the `ToggleButton` with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import ToggleButton from '@components/Basic/ToggleButton/ToggleButton'; console.log('Going back from toggle button'), 'select': () => console.log('Custom toggle logic') // Overrides default }} > Off On ``` For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/toggle-button/#guide] ## ToggleButton: Guide (1/2) #### Retrieve the ToggleButton value To retrieve the current value assigned of the `ToggleButton`, you can: - Use a `ref` to access the component instance - Use the `onChange` prop to respond when the checked state changes - Combine both to work with the value only when the ToggleButton is toggled on ##### Steps 1. Declare a `ref` variable with type `ToggleButtonRef` and pass it to the `ToggleButton` component. 2. Provide a callback to the `onChange` prop to respond to state changes. 3. Inside the callback, access the component’s value via the `ref` and act based on the current state. ```tsx import ToggleButton, { ToggleButtonRef } from '@components/Basic/ToggleButton/ToggleButton'; const App = () => { let toggleButtonRef!: ToggleButtonRef const getValue = (checked: boolean) => { if (checked) { // Log the value whenever the toggle button is toggled on console.log(toggleButtonRef.checked()); } } return ( <> ); }; export default App; ``` #### Set the value of the ToggleButton Programmatically The `ToggleButton` component lets you set the `checked` state through code. ##### Steps 1. Declare a `ref` variable with type `ToggleButtonRef` and pass it to the `ToggleButton` component. 2. Call `ref.setChecked()` from anywhere (e.g., a keyboard event or external button) to set the checked state programmatically. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/toggle-button/#guide] ## ToggleButton: Guide (2/2) ```tsx import ToggleButton, { ToggleButtonRef } from '@components/Basic/ToggleButton/ToggleButton'; const App = () => { let toggleButtonRef!: ToggleButtonRef const handleKeyPress = (e: KeyboardEvent) => { if (e.keyCode !== 13) return toggleButtonRef.setChecked(true); } return ( <> ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/] ## TwoHandleSlider The `TwoHandleSlider` component lets users select a numeric **range** by dragging two handles along a track - a lower (`start`) handle and an upper (`end`) handle. It is useful for constraints such as picking a minimum and maximum age, price, or level. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/#installation] ## TwoHandleSlider: Installation Every component ships with the boilerplate. If you are working in your own project, add `TwoHandleSlider` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add TwoHandleSlider ``` The CLI pulls in whatever `TwoHandleSlider` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/#usage] ## TwoHandleSlider: Usage To use the `TwoHandleSlider` component, specify the minimum (`min`), maximum (`max`), initial range (`value`), and step size (`step`). The `value` is an object with a `start` and an `end` key. ```tsx import TwoHandleSlider from '@components/Basic/TwoHandleSlider/TwoHandleSlider'; const App = () => { return ( <> ); }; export default App; ``` **Note:** The handles cannot cross - the `start` handle is always kept at least one `step` below the `end` handle, and vice versa. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/#api] ## TwoHandleSlider: API (1/2) #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `TwoHandleSliderRef \| undefined` | `undefined` | A reference to the component that gives you access to its methods and the underlying HTML element. Useful if you need to set the range of the slider programmatically. `value` | `{ start: number; end: number }` | `undefined` | The current range of the slider. Use this to control or set the handle positions. The prop is reactive - updating it externally moves the handles. `min` | `number` | `undefined` | The minimum value that the slider can select. `max` | `number` | `undefined` | The maximum value that the slider can select. `step` | `number` | `undefined` | The amount by which a handle’s value changes when it is moved. Determines the granularity of the slider. `onChange` | `(value: { start: number; end: number }) => void` | `undefined` | A function that is called whenever either handle’s value changes. It only fires when a value actually changes, not on every mouse move. `onChangeEnd` | `(value: { start: number; end: number }) => void` | `undefined` | A function that is called when the user finishes interacting with the slider (e.g. on mouse release, and after navigation actions settle). Useful for committing the final range. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/#api] ## TwoHandleSlider: API (2/2) Prop Name | Type | Default | Description `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the slider’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/#ref-api] ## TwoHandleSlider: Ref API To interact with the `TwoHandleSlider` programmatically, you can use the `TwoHandleSliderRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the slider’s root HTML element, useful for DOM access or styling. `value` | `Accessor<{ start: number; end: number }>` | The current range of the slider. Use `value()` to get the latest `{ start, end }`. #### Methods Method | Parameters | Return Value | Description `changeValue` | `newValue: { start: number; end: number }` | `void` | Sets both handles at once, clamped to the range and snapped to `step`. `changeStart` | `start: number` | `void` | Sets the start (lower) handle, kept one `step` below the end handle. `changeEnd` | `end: number` | `void` | Sets the end (upper) handle, kept one `step` above the start handle. `stepStart` | `direction: 1 \| -1` | `void` | Steps the start handle up (`1`) or down (`-1`) by the `step` amount. `stepEnd` | `direction: 1 \| -1` | `void` | Steps the end handle up (`1`) or down (`-1`) by the `step` amount. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/#slots] ## TwoHandleSlider: Slots (1/5) #### TwoHandleSlider.Track Customizes the slider’s track. Use this slot to apply custom classes or styles to the track area of the slider. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the slider track. `class` | `string` | `""` | Additional CSS classes to style the slider track. ##### Usage ```tsx import TwoHandleSlider from '@components/Basic/TwoHandleSlider/TwoHandleSlider'; const App = () => { return ( <> ); }; export default App; ``` #### TwoHandleSlider.Fill Customizes the filled portion of the track between the two handles, which visually represents the selected range. Use this slot to apply custom styles or classes to the fill area. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the slider fill. `class` | `string` | `""` | Additional CSS classes to style the slider fill. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/#slots] ## TwoHandleSlider: Slots (2/5) ```tsx import TwoHandleSlider from '@components/Basic/TwoHandleSlider/TwoHandleSlider'; const App = () => { return ( <> ); }; export default App; ``` #### TwoHandleSlider.Handle Customizes the draggable handles of the slider. The styling is shared, so it is applied to **both** the start and end handles. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the slider handles. `class` | `string` | `""` | Additional CSS classes to style the slider handles. `styleActive` | `JSX.CSSProperties` | `{}` | Inline styles applied to whichever handle is active while the slider is focused via keyboard/gamepad navigation. Merged on top of `style`. `classActive` | `string` | `""` | CSS class applied to the active handle while the slider is focused via navigation, replacing the default active styling. ##### Usage ```tsx import TwoHandleSlider from '@components/Basic/TwoHandleSlider/TwoHandleSlider'; const App = () => { return ( <> ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/#slots] ## TwoHandleSlider: Slots (3/5) #### TwoHandleSlider.Thumb The `TwoHandleSlider.Thumb` slot renders a small rectangular element above each handle that displays its current value. Use this slot to customize the appearance of the value indicators. The styling is shared, so it is applied to **both** thumbs. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the slider thumb (value indicator). `class` | `string` | `""` | Additional CSS classes to style the slider thumb. ##### Usage ```tsx import TwoHandleSlider from '@components/Basic/TwoHandleSlider/TwoHandleSlider'; const App = () => { return ( <> ); }; export default App; ``` **Caution:** The thumbs of the slider won’t be displayed by default. To enable them provide the `Thumb` slot inside the `TwoHandleSlider` component. #### TwoHandleSlider.Grid The `TwoHandleSlider.Grid` slot displays a visual indicator of progress along the slider’s range, dividing the track into evenly spaced segments called “pols.” Each pol marks a separation between the minimum and maximum values, helping users see how far each handle has moved. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/#slots] ## TwoHandleSlider: Slots (4/5) You can control the number of main pols (with value labels) using the `pols` prop. Additionally, by enabling the `pols-without-text` prop, smaller unlabeled pols are rendered between the main pols for finer granularity and enhanced visual feedback. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the grid container. `class` | `string` | `""` | Additional CSS classes to style the grid container. `pols` | `number` | `5` | Number of main pols (segments with value labels) to display along the slider track. `pols-without-text` | `number` | `5` | If prop is present, it renders smaller unlabeled pols between main pols for finer granularity. `pol-style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to each pol (segment marker). `pol-class` | `string` | `""` | Additional CSS classes to style each pol (segment marker). `pol-value-style` | `JSX.CSSProperties` | `{}` | Inline styles for poles displaying the slider’s current value. `pol-value-class` | `string` | `""` | Additional CSS classes for poles displaying the slider’s current value. ##### Usage ```tsx import TwoHandleSlider from '@components/Basic/TwoHandleSlider/TwoHandleSlider'; const App = () => { return ( <> ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/#slots] ## TwoHandleSlider: Slots (5/5) **Caution:** The `TwoHandleSlider.Grid` slot will only be rendered if you include it as a child of the `TwoHandleSlider` component. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/#implemented-navigation-actions] ## TwoHandleSlider: Implemented Navigation Actions The `TwoHandleSlider` component implements the following navigation actions by default. Adjustments apply to the currently **active** handle. Action Name | Behavior `move-left` | Decreases the active handle’s value by the `step` amount `move-right` | Increases the active handle’s value by the `step` amount `select` | Switches the active handle between the start and end handle You can extend the `TwoHandleSlider` with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import TwoHandleSlider from '@components/Basic/TwoHandleSlider/TwoHandleSlider'; console.log('Going back') }} /> ``` For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/#guide] ## TwoHandleSlider: Guide (1/2) #### Retrieve and use the slider range - To get the current range of the `TwoHandleSlider` component, use the `onChange` prop. It receives an object with the `start` and `end` values. ##### Steps 1. Define a state variable (e.g., using `createSignal`) to store the slider range. 2. Pass a callback to the `onChange` prop that updates this state variable. 3. Use the state variable wherever you need the slider’s range. ```tsx import TwoHandleSlider from '@components/Basic/TwoHandleSlider/TwoHandleSlider'; import { createSignal } from 'solid-js'; const App = () => { const [range, setRange] = createSignal({ start: 20, end: 60 }); return ( <> setRange(value)} value={{ start: 20, end: 60 }} max={100} min={0} step={1} />
{range().start} - {range().end}
); }; export default App; ``` #### React only to the final range - The `onChange` prop fires every time a value changes while dragging. If you only care about the final range once the user finishes interacting (e.g. to avoid expensive work on every step), use the `onChangeEnd` prop instead. `onChangeEnd` is called when the user releases a handle after a drag, and after navigation actions (`move-left` / `move-right`) settle. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/two-handle-slider/#guide] ## TwoHandleSlider: Guide (2/2) ```tsx import TwoHandleSlider from '@components/Basic/TwoHandleSlider/TwoHandleSlider'; import { createSignal } from 'solid-js'; const App = () => { const [range, setRange] = createSignal({ start: 20, end: 60 }); return ( <> setRange(value)} value={{ start: 20, end: 60 }} max={100} min={0} step={1} />
{range().start} - {range().end}
); }; export default App; ``` #### Set the range of the slider programmatically The `TwoHandleSlider` component lets you set the range through code. Use `changeValue` to set both handles at once, or `changeStart` / `changeEnd` to move a single handle. ##### Steps 1. Declare a `ref` variable with type `TwoHandleSliderRef` and pass it to the `TwoHandleSlider` component. 2. Call `ref.changeValue()` (or `ref.changeStart()` / `ref.changeEnd()`) from anywhere (e.g., a keyboard event or external button) to set the range programmatically. ```tsx import TwoHandleSlider, { TwoHandleSliderRef } from '@components/Basic/TwoHandleSlider/TwoHandleSlider'; const App = () => { let sliderRef!: TwoHandleSliderRef; const handleKeyPress = (e: KeyboardEvent) => { if (e.keyCode !== 13) return sliderRef.changeValue({ start: 10, end: 90 }); } return ( <> ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/xy-slider/] ## XYSlider The `XYSlider` component allows users to select a value in a two-dimensional space, providing a more intuitive way to select values that require both horizontal and vertical input. The slider automatically handles the selection of a value between a minimum and maximum range on the horizontal and vertical axes. The slider itself provides slots to customize its appearance and behavior. For example you can customize its background or the handle to make it more visually appealing or to fit the design of your UI. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/xy-slider/#installation] ## XYSlider: Installation Every component ships with the boilerplate. If you are working in your own project, add `XYSlider` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add XYSlider ``` The CLI pulls in whatever `XYSlider` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/xy-slider/#usage] ## XYSlider: Usage Using the `XYSlider` component is straightforward. You can import it and use it in your application as follows: **index.tsx:** ```tsx import XYSlider from '@components/Basic/XYSlider/XYSlider'; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/xy-slider/#api] ## XYSlider: API (1/2) #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `XYSliderRef \| undefined` | `undefined` | A reference to the component that gives you access to its methods and the underlying HTML element. Useful if you need to set the value of the slider programmatically. `value` | `{x:number, y: number}` | `{ x: 50, y: 50 }` | The current value of the slider. Use this to control or set the slider’s position. `minX` | `number` | `0` | The minimum value that the slider can select on the X-axis. `minY` | `number` | `0` | The minimum value that the slider can select on the Y-axis. `maxX` | `number` | `100` | The maximum value that the slider can select on the X-axis. `maxY` | `number` | `100` | The maximum value that the slider can select on the Y-axis. `step` | `number` | `1` | The base unit for value changes. Used primarily for gamepad inputs to calculate movement speed and precision. `onChange` | `(value: {x:number, y: number}) => void` | `undefined` | A function that is called every time the slider’s value has changed. It can be used to retrieve the up to date value of the slider. `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/xy-slider/#api] ## XYSlider: API (2/2) Prop Name | Type | Default | Description `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the stepper’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/xy-slider/#ref-api] ## XYSlider: Ref API To interact with the `XYSlider` programmatically, you can use the `XYSliderRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the XYSlider’s root HTML element, useful for DOM access or styling. `value` | `Accessor<{x: number, y: number}>` | The current value of the slider. Use `value()` to get the latest value. #### Methods Method | Parameters | Return Value | Description `changeValue` | `newValue: {x: number, y: number}` | `void` | Programmatically sets a new value for the XYSlider. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/xy-slider/#slots] ## XYSlider: Slots (1/2) #### XYSlider.Background Customizes the slider’s background. Use this slot to apply add a custom background to the slider, such as a gradient or an image. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the slider’s background. `class` | `string` | `""` | Additional CSS classes to style the slider’s background. `children` | `JSX.Element` | `""` | Content to be rendered inside the background slot. This can be used to add custom elements or styles. ##### Usage ```tsx import XYSlider from '@components/Basic/XYSlider/XYSlider'; import Absolute from '@components/Layout/Absolute/Absolute'; const App = () => { return ( Custom Background ); }; export default App; ``` #### XYSlider.Handle Customizes the draggable handle of the slider. Use this slot to apply custom styles or classes to the slider’s handle. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the slider’s handle. `class` | `string` | `""` | Additional CSS classes to style the slider’s handle. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/xy-slider/#slots] ## XYSlider: Slots (2/2) ```tsx import XYSlider from '@components/Basic/XYSlider/XYSlider'; const App = () => { return ( ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/xy-slider/#implemented-navigation-actions] ## XYSlider: Implemented Navigation Actions The `XYSlider` component implements the following navigation actions by default: Action Name | Behavior `pan` | Moves the slider handle based on 2D axis input. Includes acceleration and smoothing logic. **Note:** The XYSlider uses the `step` prop to determine base movement speed. It employs a dynamic acceleration system where pushing the stick further increases the speed multiplier, allowing for both precise adjustments (slight tilt) and rapid movement (full tilt). Read more here You can extend the XYSlider with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import XYSlider from '@components/Basic/XYSlider/XYSlider'; console.log('Selecting XYSlider'), 'pan': (_, axis: [number, number]) => console.log(`x: ${axis[0]}, y: ${axis[1]}`), }} /> ``` For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/xy-slider/#guide] ## XYSlider: Guide (1/2) #### Retrieve and use the slider value - To get the current value of the `XYSlider` component, use the `onChange` prop. - When you save the value in a state variable, you can use it in your UI to display or process the slider’s value. ##### Steps 1. Define a state variable (e.g., using `createSignal`) to store the slider value. 2. Pass a callback to the `onChange` prop that updates this state variable. 3. Use the state variable wherever you need the slider’s value. ```tsx import XYSlider from '@components/Basic/XYSlider/XYSlider'; import { createSignal } from 'solid-js'; const App = () => { const [sliderValue, setSliderValue] = createSignal({x: 50, y: 50}); return ( <> setSliderValue(value)} />
X: {sliderValue().x} | Y: {sliderValue().y}
); }; export default App; ``` #### Set the value of the slider programmatically The `Slider` component lets you set the `value` through code. ##### Steps 1. Declare a `ref` variable with type `XYSliderRef` and pass it to the `XYSlider` component. 2. Call `ref.changeValue()` from anywhere (e.g., a keyboard event or external button) to set the value programmatically. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/basic/xy-slider/#guide] ## XYSlider: Guide (2/2) ```tsx import XYSlider { XYSliderRef } from '@components/Basic/XYSlider/XYSlider'; const App = () => { let sliderRef!: XYSliderRef; const handleKeyPress = (e: KeyboardEvent) => { if (e.keyCode !== 13) return sliderRef.changeValue({x: 150, y: 50}); } return ( ); }; export default App; ``` #### Adjusting gamepad movement speed and precision The `XYSlider` is designed to work out-of-the-box with the `pan` action of the `Navigation` component which uses the right analogue stick of the gamepad. To tune the feel of the gamepad control, adjust the step prop. - A smaller step (e.g., 1) allows for pixel-perfect precision but might be slow on large ranges. - A larger step (e.g., 10) makes the slider faster but less precise. ```ts // Increases base speed for large range ``` **Note:** If you are working with very small values (e.g., 0.0 to 1.0), consider using a smaller step (e.g., 0.1) to maintain precision. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/] ## Carousel The `Carousel` component is a flexible and feature-rich solution for displaying a series of items in a sliding format. It offers support for features like pagination, navigation controls, and customizable item slots, making it ideal for showcasing images, cards, or other content in a carousel layout. This component is built using foundational elements, including: - Pagination for rendering pagination controls. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#installation] ## Carousel: Installation Every component ships with the boilerplate. If you are working in your own project, add `Carousel` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Carousel ``` The CLI pulls in whatever `Carousel` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#usage] ## Carousel: Usage To use the `Carousel` component, simply import it and include it in your JSX. You can customize it with various props and slots to suit your specific requirements. **Tip:** For detailed usage instructions, examples, and customization options, refer to the Guide section. **index.tsx:** ```tsx import { For } from 'solid-js'; import Flex from '@components/Layout/Flex/Flex'; import Carousel from '@components/Complex/Carousel/Carousel'; {(item) => {item} } ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#api] ## Carousel: API (1/2) #### Carousel Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the carousel’s wrapper element. `class` | `string` | `""` | Additional CSS classes to apply to the carousel’s wrapper element. `ref` | `CarouselRef \| undefined` | `undefined` | A reference to the component, providing access to its methods and the underlying HTML element. `itemWidth` | `number` | `100` | Specifies the width of each carousel item as a percentage. This determines how wide each item will appear within the carousel. `itemGap` | `number` | `0` | Defines the gap between carousel items as a percentage. This determines the spacing between items in the carousel. `itemsAlignment` | `'start' \| 'center' \| 'end'` | `start` | Controls the alignment of items within the carousel. Options include `start`, `center`, and `end`, which determine how items are aligned along the main axis of the carousel. `groupItems` | `boolean` | `false` | When set to `true`, groups items together based on the `itemWidth` and `itemGap` values, enabling a page-like display where multiple items are shown at once. `leadingAndTrailingSpaces` | `boolean` | `true` | Determines whether to add leading and trailing spaces to the items. Setting this to `false` creates a more compact layout without extra padding on the sides. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the carousel. See the Navigation component documentation for details. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#api] ## Carousel: API (2/2) Prop Name | Type | Default | Description `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the carousel’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#ref-api] ## Carousel: Ref API (1/2) To interact with the `Carousel` programmatically, you can use the `CarouselRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the carousel’s underlying HTML element, useful for accessing DOM properties or applying additional styles. `itemsContainer` | `HTMLDivElement` | A reference to the container holding all carousel items, useful for directly manipulating the layout or applying styles to the container. #### Methods --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#ref-api] ## Carousel: Ref API (2/2) Method Name | Parameters | Return Value | Description `next` | None | `void` | Moves the carousel to the next item. If `groupItems` is enabled, it moves to the next group of items. `prev` | None | `void` | Moves the carousel to the previous item. If `groupItems` is enabled, it moves to the previous group of items. `scrollTo` | `page: number` | `void` | Scrolls the carousel to a specific page or item. The `page` parameter is zero-based, with `0` referring to the first page. If `groupItems` is enabled, it scrolls to the specified group of items. `activePage` | None | `number` | Returns the index of the currently active page or item. If `groupItems` is enabled, it returns the index of the active group of items. `pagesCount` | None | `number` | Returns the total number of pages or items in the carousel. If `groupItems` is enabled, it returns the total number of groups of items. `translateItemsContainer` | None | `void` | Translates the items container to the current active page or item. This method is used internally to update the position of the items container but can also be used manually for custom pagination logic. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#slotscomponents] ## Carousel: Slots/Components (1/6) The `Carousel` component exposes multiple slots and subcomponents that let you fully customize its layout and behavior: - **Carousel.Items** - Container for all carousel items. - **Carousel.Item** - Defines a single item inside `Carousel.Items`. - **Carousel.Pagination** - Displays pagination controls. - **Carousel.Pagination.Item** - Represents a single pagination dot or item. - **Carousel.Pagination.Controls** - Slot for providing custom pagination controls, or disabling them entirely. - **Carousel.Next** - Navigation button to move to the next item. - **Carousel.Prev** - Navigation button to move to the previous item. #### Carousel.Items `Carousel.Items` acts as the container for all carousel content. It wraps the individual `Carousel.Item` components and handles the sliding layout automatically. You can place `Carousel.Items` anywhere inside the `Carousel` component (top, bottom, or middle). It will always apply the proper structure and styles. This makes it flexible to combine with other layout components like `Flex` or `Grid`. For example, to display items and pagination side by side: ```tsx Item 1 Item 2 Item 3 Item 4 ``` ##### Internal structure --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#slotscomponents] ## Carousel: Slots/Components (2/6) Internally, `Carousel.Items` renders two nested containers: 1. **Wrapper** - Defines the visible area and hides overflow. 2. **Items container** - Holds the actual items and is translated along the X axis based on the active page/item. This design gives you flexibility: you can apply custom styles or classes to either container, while the carousel logic is preserved. ##### Carousel.Items Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to the wrapper container. `itemsContainerStyle` | `JSX.CSSProperties` | `{}` | Inline styles applied to the inner items container. `class` | `string` | `""` | CSS classes applied to the wrapper container. `itemsContainerClass` | `string` | `""` | CSS classes applied to the inner items container. ##### Container animation The items container uses a transform transition with a default duration of 0.2s. You can override this behavior by providing your own transition or disabling it entirely. This can be done by applying a custom class or inline style through the `itemsContainerStyle` or `itemsContainerClass` props. For example: ```tsx // Increase the transition duration when switching items // Completely disable the transition ``` #### Carousel.Item --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#slotscomponents] ## Carousel: Slots/Components (3/6) The `Carousel.Item` component defines a single item inside the `Carousel.Items` container. Each `Carousel.Item` represents one element in the carousel - this could be an image, a card, or any other type of content you’d like to showcase. ##### Carousel.Item Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied directly to the carousel item element. `style-selected` | `JSX.CSSProperties` | `{}` | Inline styles applied when the item is marked as selected. `class` | `string` | `""` | Additional CSS classes applied to the carousel item element. `class-selected` | `string` | `""` | Additional CSS classes applied when the item is selected. `selected` | `boolean` | `false` | Marks the item as the currently selected one. **Caution:** The `style-selected`, `class-selected`, and `selected` props only take effect when the `Carousel` component has its `groupItems` prop set to false. If `groupItems` is true, these props will be ignored. ##### Usage ```tsx Item 1 Item 2 Item 3 Item 4 ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#slotscomponents] ## Carousel: Slots/Components (4/6) In this example, the second item is automatically positioned in the center of the carousel, marked as selected, and scaled up by `1.1` of its original size. #### Carousel.Pagination The `Carousel.Pagination` component renders pagination controls, allowing users to navigate through carousel items via buttons or indicators. Under the hood, it uses the Pagination component, so you can leverage the same props and slots to fully customize its behavior and appearance. You can place `Carousel.Pagination` anywhere inside the `Carousel`. It automatically syncs with the carousel’s active page and items. Styling and additional classes can be applied via the `style` and `class` props. To customize the behavior of pagination items or controls, you can use the `Carousel.Pagination.Item` and `Carousel.Pagination.Controls` slots. For instance, you can design your own buttons, indicators, or even disable them entirely. **Note:** Pagination is **disabled by default**. To enable it, you must include the `Carousel.Pagination` component within the `Carousel`. **Tip:** You can disable the default pagination controls and replace them with your own using the `Carousel.Pagination.Controls` slot: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#slotscomponents] ## Carousel: Slots/Components (5/6) ```tsx Item 1 Item 2 Item 3 Item 4 ``` This approach is handy when you want to hide the built-in controls and instead use `Carousel.Prev` and `Carousel.Next` components to build fully custom navigation. #### Carousel.Next/Carousel.Prev The `Carousel.Next` and `Carousel.Prev` components provide custom navigation controls for the carousel. They let users move forward or backward through the carousel items with a simple click. These components can be placed anywhere inside the `Carousel` and will automatically sync with the carousel’s active page and items. You can also customize their appearance by adding text, icons, or any other elements inside them. ##### Props --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#slotscomponents] ## Carousel: Slots/Components (6/6) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied directly to the next/prev button element. `class` | `string` | `""` | Additional CSS classes for the next/prev button element. `class-disabled` | `string` | `""` | Additional CSS classes applied when the button is disabled. Buttons are disabled automatically if there are no more items to scroll left or right. `children` | `JSX.Element` | `undefined` | Content rendered inside the button. Can be an icon, text, or any element. Defaults to an arrow icon if no content is provided. ##### Usage ```tsx Item 1 Item 2 Item 3 Item 4 ``` In this example, the default pagination controls are hidden and replaced with the `Carousel.Prev` and `Carousel.Next` buttons. Both buttons are placed next to the pagination, allowing users to navigate between carousel items manually. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (1/15) To use the `Carousel` component effectively, start by defining your goals - how you want the items to appear and behave. The `Carousel` is designed to be flexible, so its configuration depends on whether you want to highlight individual items or focus on the entire group. The following considerations will help you set it up: - **Item vs. group focus**: Use the `groupItems` prop to decide whether the emphasis should be on a single selected item or the entire collection. - **Leading and trailing space**: Control extra spacing at the start and end with the `leadingAndTrailingSpaces` prop. Setting it to `false` removes the side padding, creating a more compact layout. - **Size and spacing**: Adjust `itemWidth` and `itemGap` to define item dimensions and spacing. - **Alignment**: Use `itemsAlignment` (`start`, `center`, or `end`) to control how items are aligned inside the carousel. - **Navigation**: Choose between the built-in pagination (`Carousel.Pagination`) or custom navigation controls (`Carousel.Next and Carousel.Prev`). The following sections illustrate different approaches based on these options. #### Highlighting a Selected Item When you want to emphasize the active item, leave `groupItems={false}` or omit it. This allows you to style individual items when they are selected using the `style-selected` or `class-selected` props of `Carousel.Item`. In the example below, each item takes up `40%` width with a `5%` gap, and the active item is centered (`itemsAlignment="center"`). --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (2/15) ```tsx import { For } from 'solid-js'; import Flex from '@components/Layout/Flex/Flex'; import Carousel from '@components/Complex/Carousel/Carousel'; const App = () => { const items = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5']; return ( {(item) => {item} } ); }; export default App; ``` To make the selected item stand out, add custom styles via `style-selected`: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (3/15) ```tsx import { For } from 'solid-js'; import Flex from '@components/Layout/Flex/Flex'; import Carousel from '@components/Complex/Carousel/Carousel'; const App = () => { const items = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5']; return ( {(item) => {item} } ); }; export default App; ``` ##### Removing leading and trailing spaces By default, the `Carousel` component adds extra spacing before the first item and after the last one. This helps create a more open layout with padding on the sides. If you’d rather have a compact layout without these side gaps, you can disable this behavior by setting the `leadingAndTrailingSpaces` prop to `false`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (4/15) ```tsx import { For } from 'solid-js'; import Flex from '@components/Layout/Flex/Flex'; import Carousel from '@components/Complex/Carousel/Carousel'; const App = () => { const items = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5']; return ( {(item) => {item} } ); }; export default App; ``` ##### Align items differently You can also control how items are aligned within the carousel using the `itemsAlignment` prop. Setting it to `start` or `end` shifts the items accordingly, giving the carousel a different visual flow. **itemsAlignment=‘start’** **itemsAlignment=‘end’** #### Page like display of items --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (5/15) For a page-like experience, use the `groupItems` prop. When enabled, items are grouped together based on the defined `itemWidth` and `itemGap`. Navigation will then move one group at a time instead of a single item. **Caution:** When `groupItems` is set to `true`: - The `selected`, `style-selected`, and `class-selected` props of `Carousel.Item` are ignored. - The `leadingAndTrailingSpaces` setting is also ignored, as the carousel will always remove side spacing in this mode. #### Creating custom controls If you’d like to replace the default navigation buttons, you can use the `Carousel.Next` and `Carousel.Prev` components to build your own controls. You can also override or hide the built-in pagination buttons by customizing the `Carousel.Pagination.Controls` slot. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (6/15) ```tsx import { For } from 'solid-js'; import Flex from '@components/Layout/Flex/Flex'; import Carousel from '@components/Complex/Carousel/Carousel'; const App = () => { const items = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5']; return ( {(item) => {item} } ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (7/15) #### Adding custom scrolling behavior You can also control the carousel programmatically using a `CarouselRef` in combination with `next` and `prev` methods that lets you scroll to the next or previous item. With this approach, you can add custom navigation logic - for example, scrolling when certain keyboard keys are pressed, or when the user scrolls the mouse wheel. ##### Scrolling with the mouse wheel To enable mouse wheel scrolling, simply listen for the `wheel` event on the carousel element and call `ref.next()` or `ref.prev()` depending on the scroll direction. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (8/15) ```tsx import { For } from 'solid-js'; import Flex from '@components/Layout/Flex/Flex'; import Carousel, { CarouselRef } from '@components/Complex/Carousel/Carousel'; const App = () => { const items = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5']; let ref!: CarouselRef; const scrollCarousel = (event: WheelEvent) => { event.preventDefault(); event.deltaY > 0 ? ref.next() : ref.prev() }; return ( {(item) => {item} } ); }; export default App; ``` ##### Keyboard arrow keys scrolling You can also navigate the carousel using the keyboard’s arrow keys. Simply add a `keydown` listener and call the `next` or `prev` methods depending on which key is pressed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (9/15) ```tsx import { For, onMount, onCleanup } from 'solid-js'; import Flex from '@components/Layout/Flex/Flex'; import Carousel, { CarouselRef } from '@components/Complex/Carousel/Carousel'; const App = () => { const items = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5']; let ref!: CarouselRef; const scrollCarouselWithKey = (event: KeyboardEvent) => { event.preventDefault(); event.keyCode === 39 ? ref.next() : event.keyCode === 37 ? ref.prev() : null; }; onMount(() => { document.addEventListener('keydown', scrollCarouselWithKey); }); onCleanup(() => { document.removeEventListener('keydown', scrollCarouselWithKey); }); return ( {(item) => {item} } ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (10/15) ##### Continuous scrolling while holding down You can also enable continuous scrolling when a button is held down. To achieve this: - Use custom controls with `Carousel.Next` and `Carousel.Prev`. - Pass empty `click` handlers to disable their default behavior. - Create a function that repeatedly triggers scrolling while the button is held. - Use `setTimeout` for the initial delay and `setInterval` for continuous scrolling. - Add a `mouseup` listener to stop the scroll when the button is released. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (11/15) ```tsx import { For, onMount, onCleanup } from 'solid-js'; import Flex from '@components/Layout/Flex/Flex'; import Carousel, { CarouselRef } from '@components/Complex/Carousel/Carousel'; const App = () => { const items = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5']; let ref!: CarouselRef; let bounceTimeout: any, bounceInterval: any; const bounce = (scrollCarouselCallback: () => void) => { return () => { scrollCarouselCallback(); // Add event listener for mouseup to stop the continuous scrolling document.addEventListener('mouseup', clearTimers, { once: true }); // Clear any existing timeouts or intervals clearTimers(); bounceTimeout = setTimeout(() => { bounceInterval = setInterval(() => { scrollCarouselCallback(); }, 100); }, 200) } } const clearTimers = () => { if (bounceTimeout) { clearTimeout(bounceTimeout); bounceTimeout = null; } if (bounceInterval) { clearInterval(bounceInterval); bounceInterval = null; } } return ( {(item) => {item} } { }} mousedown={bounce(() => ref.prev())} /> { }} mousedown={bounce(() => ref.next())} /> ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (12/15) #### Extending the Carousel With Navigation 2.0.0 The `Carousel` component is highly adaptable and can be integrated with the `Navigation` system to support various keyboard and button inputs. Depending on your UI’s depth, you might want the carousel to react globally to certain inputs or strictly only when it is in focus. The following examples demonstrate two common patterns for integrating the `Carousel` with the `Navigation` system. ##### Pattern A: Tab-style This approach is perfect for “Top-level” carousels, such as main menu categories or shop tabs. In this scenario, we want specific buttons (like Shoulder Buttons or Q/E) to control the carousel regardless of where the focus is. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (13/15) ```tsx import Carousel, { CarouselRef } from '@components/Complex/Carousel/Carousel'; import Navigation from '@components/Utility/Navigation/Navigation'; import { ActionMap } from '@components/Utility/Navigation/types'; const App = () => { // Declare carousel ref let carouselRef!: CarouselRef; // Define actions for shifting tabs const customActions: ActionMap = { 'carousel-prev': { key: { binds: ['Q'], type: ['press', 'hold'] }, button: { binds: ['left-shoulder'], type: 'hold' }, callback: () => carouselRef.prev() }, 'carousel-next': { key: { binds: ['E'], type: ['press', 'hold'] }, button: { binds: ['right-shoulder'], type: 'hold' }, callback: () => carouselRef.next() }, }; return ( // Provide actions to the Navigation component and attach ref to carousel {/* Carousel content */} ); } ``` ##### Pattern B: Scoped Directional Control (onAction) This pattern is ideal for nested carousels or lists (like a character selection screen). By using the built-in `onAction` prop, the carousel only responds to Arrow Keys or the D-Pad when its element is explicitly focused. This prevents “input bleeding,” where one button press accidentally moves multiple menus on the same page. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (14/15) ```tsx import Carousel, { CarouselRef } from '@components/Complex/Carousel/Carousel'; import Navigation from '@components/Utility/Navigation/Navigation'; import { ActionMap } from '@components/Utility/Navigation/types'; const App = () => { // Declare carousel ref let carouselRef!: CarouselRef; // Initialize: Store the API and focus the element const initCarouselRef = (api: CarouselRef) => { carouselRef = api; api.element.focus(); // Must be focused to receive 'move' actions } return ( carouselRef.prev(), 'move-right': () => carouselRef.next(), }} > {/* Carousel content */} ); } ``` ##### Key Considerations --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/carousel/#guide] ## Carousel: Guide (15/15) - **Differences**: Custom actions (Pattern A) are excellent for high-level navigation that should always be available and doesn’t rely on the element to be focused. Scoped actions (Pattern B) provide finer control, ensuring that directional inputs only affect the carousel the user is currently interacting with. - **Managing Focus**: When using `onAction`, remember that the Carousel’s element should be focused. - **Input Flexibility**: You are not limited to these two patterns. Because the `Navigation` system and the `CarouselRef` are decoupled, you can mix and match these approaches—for example, using LB/RB for fast-paging while using the D-Pad for precise single-item movement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/color-picker/] ## Color picker The `ColorPicker` component is a powerful UI element designed for seamless color selection. It is ideal for applications such as design tools, image editors, or any interface requiring color customization. As part of the complex components in Gameface UI, the `ColorPicker` combines multiple basic components to deliver advanced functionality. It enables users to adjust hue, saturation, brightness, and transparency, while providing a color preview area for visual feedback. Internally, the component utilizes the following basic components: - XYSlider for adjusting brightness and saturation. - Slider for controlling hue and alpha (transparency). - Segment for toggling the color preview mode between HEX and RGBA. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/color-picker/#installation] ## Color picker: Installation Every component ships with the boilerplate. If you are working in your own project, add `ColorPicker` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add ColorPicker ``` The CLI pulls in whatever `ColorPicker` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/color-picker/#usage] ## Color picker: Usage To use the `ColorPicker` component, simply import and render it as shown below: **index.tsx:** ```tsx import ColorPicker from '@components/Complex/ColorPicker/ColorPicker'; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/color-picker/#api] ## Color picker: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the color picker’s wrapper element. `class` | `string` | `""` | Additional CSS classes to apply to the color picker’s wrapper element. `ref` | `ColorPickerRef \| undefined` | `undefined` | A reference to the component, providing access to its methods and the underlying HTML element. `value` | `string` | `rgba(255, 0, 0, 1)` | Initial value of the color picker. Accepts colors as strings in HEX or RGBA format. `size` | `'S' \| 'M' \| 'L' \| 'XL'` | `'L'` | Sets the size of the color picker. The size affects the overall dimensions and font sizes within the component. Ideal for quick customization. `onChange` | `(value: ColorData) => void` | `undefined` | A callback function triggered whenever the color changes. It can be used to retrieve the updated color value. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the color picker. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the color picker’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/color-picker/#ref-api] ## Color picker: Ref API To interact with the `ColorPicker` programmatically, you can use the `ColorPickerRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the color picker’s root HTML element, useful for DOM access or styling. #### Methods Method | Parameters | Return Value | Description `value` | None | `{rgba: string, hex: string}` | Retrieves the currently selected color value from the color picker into rgba and hex format. `changeColor` | `newColor: string` | `void` | Updates the color picker programmatically with a new color. This method accepts color strings in either `RGBA` or `HEX` format, which are automatically converted to `ColorData` internally. #### ColorData Type Property | Type | Description `h` | `number` | Represents the hue of the color (0-360). `s` | `number` | Represents the saturation of the color (0-100). `v` | `number` | Represents the brightness of the color (0-100). `a` | `number` | Represents the alpha (transparency) of the color (0-1). --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/color-picker/#color-picker-utilities] ## Color picker: Color Picker Utilities To simplify color format conversions, utility methods are available for translating between `HSVA`, `RGBA`, and `HEX`. These methods can be imported from `@components/Complex/ColorPicker/colorPickerUtils`: ```tsx import { RGBAOrHEXToHSVA, RGBAToHSVA, parseHSVAColor } from "@components/Complex/ColorPicker/colorPickerUtils"; ``` #### RGBAOrHEXToHSVA(color: string) => ColorData Converts a color string in `RGBA` or `HEX` format to `ColorData`. The method automatically detects the input format and performs the conversion. ```tsx import { RGBAOrHEXToHSVA } from "@components/Complex/ColorPicker/colorPickerUtils"; RGBAOrHEXToHSVA('rgba(0, 0, 0, 0.5)'); // Returns ColorData: { h: 0, s: 0, v: 0, a: 0.5 } RGBAOrHEXToHSVA('#00000080'); // Returns ColorData: { h: 0, s: 0, v: 0, a: 0.5 } ``` #### RGBAToHSVA(rgba: string) => ColorData Converts an `RGBA` color string to `ColorData`. ```tsx import { RGBAToHSVA } from "@components/Complex/ColorPicker/colorPickerUtils"; RGBAToHSVA('rgba(0, 0, 0, 0.5)'); // Returns ColorData: { h: 0, s: 0, v: 0, a: 0.5 } ``` #### parseHSVAColor(color: ColorData) => string Converts `ColorData` to a color string in `RGBA` or `HEX` format. ```tsx import { parseHSVAColor } from "@components/Complex/ColorPicker/colorPickerUtils"; parseHSVAColor({ h: 0, s: 0, v: 0, a: 1 }); // Returns { rgba: 'rgba(0, 0, 0, 1)', hex: '#000000FF' } ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/color-picker/#guide] ## Color picker: Guide (1/6) #### Setting an initial value To initialize the color picker with a value other than the default `rgba(255, 0, 0, 1)`, use the `value` prop. This prop accepts color strings in either `RGBA` or `HEX` format. Internally, the component converts the provided value to `HSVA` format for internal processing. ```tsx import ColorPicker from '@components/Complex/ColorPicker/ColorPicker'; const App = () => { return ( // Or ); }; export default App; ``` **Note:** The `value` prop is non-reactive and is intended only for setting the initial color of the picker. To programmatically control the color, use the `ref.changeColor` method. #### Programmatically changing the color picker value To update the color picker value programmatically, use the `ref` prop to access the component’s instance. The `changeColor` method allows you to set a new color. The method accepts string values in `RGBA` or `HEX` format, which are automatically converted to `ColorData` internally. ```tsx import ColorPicker from '@components/Complex/ColorPicker/ColorPicker'; const App = () => { let colorPickerRef!: ColorPickerRef; const changeColor = () => { if (colorPickerRef) { // Update the color to rgba(0, 0, 0, 0.5) colorPickerRef.changeColor('rgba(0, 0, 0, 0.5)'); } }; return ( <> ); }; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/color-picker/#guide] ## Color picker: Guide (2/6) #### Retrieve the color picker value To access the current value of the color picker, use the `ref` prop to obtain a reference to the component instance. This reference provides methods for interacting with the color picker. The `value` method retrieves the current color in `{rgba: string, hex: string}` format. If you need the color in `HSVA` format, use the `RGBAOrHEXToHSVA` utility method to convert the `rgba` or `hex` string to `ColorData` which represents the color in hue, saturation, value, and alpha components. ```tsx import ColorPicker from '@components/Complex/ColorPicker/ColorPicker'; const App = () => { let colorPickerRef!: ColorPickerRef; const getColor = () => { if (colorPickerRef) { // Retrieve the current color value from the color picker const color = colorPickerRef.value(); console.log(color); // Logs the color in RGBA and HEX format // Example output: { rgba: 'rgba(0, 0, 0, 0.5)', hex: '#00000080' } } }; return ( <> ); }; ``` #### Listen to color changes To respond to color changes in the `ColorPicker`, use the `onChange` prop. This prop accepts a callback function that receives the updated color value as an argument. The value is provided in `ColorData` format, which includes hue, saturation, brightness, and alpha components. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/color-picker/#guide] ## Color picker: Guide (3/6) Because the provided value of the `onChange` callback is in `ColorData` format, you can use the `parseHSVAColor` utility method to convert it to a string in either `RGBA` or `HEX` format if needed. ```tsx import ColorPicker, { ColorData } from '@components/Complex/ColorPicker/ColorPicker'; import { parseHSVAColor } from '@components/Complex/ColorPicker/colorPickerUtils'; const App = () => { const handleColorChange = (color: ColorData) => { console.log('Color changed:', color); // Example output: { h: 0, s: 0, v: 0, a: 0.5 } // Convert to RGBA or HEX string if needed const rgbaString = parseHSVAColor(color).rgba; // 'rgba(0, 0, 0, 0.5)' const hexString = parseHSVAColor(color).hex; // '#00000080' console.log('RGBA:', rgbaString); console.log('HEX:', hexString); }; return ( ); }; ``` #### Customizing the component The `ColorPicker` component can be tailored to fit your application’s design by using the `style` and `class` props. These props allow you to apply custom styles and CSS classes to the wrapper element of the color picker. ```tsx import ColorPicker from '@components/Complex/ColorPicker/ColorPicker'; const App = () => { return ( ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/color-picker/#guide] ## Color picker: Guide (4/6) **Note:** To customize the internal components of the `ColorPicker`, such as the `XYSlider` or `Slider`, you can modify the `ColorPicker` component directly or create a copy of it for your specific needs. These internal components are designed to be flexible and can be adjusted using their own props, but no additional customization options are provided for them within the `ColorPicker`. #### Extending the Color Picker With Navigation 2.0.0 The `ColorPicker` component can be extended to work with the `Navigation` component to allow for keyboard or gamepad navigation. Since the `ColorPicker` is built using basic components like `XYSlider`, `Slider` and `Segment` , which are compatible with the `Navigation` system, you can wrap the `ColorPicker` in a `Navigation` component to enable navigation support. To achieve this, follow these steps: 1. Make sure the `ColorPicker` is a descendant of a `Navigation` component in your component tree. 2. Wrap the components in the `ColorPicker` you wish to enable navigation for with the `Navigation.Area` component. 3. Optionally, add focus styles for all components that will be navigable for visual indication. ##### Example setup In this example we will modify the `ColorPicker` component to include `Navigation.Area` around the internal components that we want to be navigable. The component’s internal navigation setup will handle the interactions out of the box! --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/color-picker/#guide] ## Color picker: Guide (5/6) ```tsx const ColorPicker: ParentComponent = (props) => { // Existing color picker code... return (
setSelectedFormat(value)}> HEX RGBA
); } ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/color-picker/#guide] ## Color picker: Guide (6/6) ##### CSS for focus styles For the visual focus indication, in this example we add a border to the slider handles and a box-shadow to the segment when the components receive focus. Since there are multiple sliders in the `ColorPicker`’s components, we can create a SCSS mixin to handle the focus styles for the slider handles. Here’s how you can implement it: ```scss @mixin handle-focus($slider-name) { &:focus { .#{$slider-name} { border: 0.2vmax solid rgb(197, 197, 197); } } } .XYSlider { width: 100%; border: none; margin-bottom: 0.5em; height: 10em; @include handle-focus('XYSlider-handle'); &-handle { width: 1.5em; height: 1.5em; } } .hue-slider, .alpha-slider { width: 85%; height: 0.75em; padding: 0; margin: 0; margin-top: 0.5em; margin-bottom: 0.5em; border-radius: 0.5em; @include handle-focus('slider-handle'); } .segment { margin-top: 0.5em; margin-bottom: 0.5em; &:focus { box-shadow: 0 0 0.5vmax rgba(0, 0, 0, 0.2); } } ``` ##### Final result --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/] ## Radial Menu The `RadialMenu` component is an interactive circular menu designed for quick selection among multiple options arranged radially around a center point. It supports mouse and controller input, visual indicators, and customizable slice spacing, making it ideal for in-game weapon wheels, tool selectors, or compact UI menus. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#installation] ## Radial Menu: Installation Every component ships with the boilerplate. If you are working in your own project, add `RadialMenu` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add RadialMenu ``` The CLI pulls in whatever `RadialMenu` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#usage] ## Radial Menu: Usage (1/2) To use the `Radial-menu` component, simply import it and include it in your JSX. You can customize it with various props and slots to suit your specific requirements. **Tip:** For detailed usage instructions, examples, and customization options, refer to the Guide section. **index.tsx:** --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#usage] ## Radial Menu: Usage (2/2) ```tsx // Assets import import Weapon1 from "@assets/wheel/weapon1.png"; import Weapon2 from "@assets/wheel/weapon2.png"; import Weapon3 from "@assets/wheel/weapon3.png"; import Weapon4 from "@assets/wheel/weapon4.png"; import Weapon5 from "@assets/wheel/weapon5.png"; import Weapon6 from "@assets/wheel/weapon6.png"; import Center from "@assets/wheel/GameMessage_AchievmentIcon.png"; import { For } from 'solid-js'; import RadialMenu from "@components/Complex/RadialMenu/RadialMenu"; import Image from "@components/Media/Image/Image"; {(item) => (
)}
``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#api] ## Radial Menu: API #### RadialMenu Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the radial menu’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the radial menu’s root element. `ref` | `RadialMenuRef \| undefined` | `undefined` | A reference to the component, providing access to its methods and the underlying HTML element. `opened` | `boolean` | `false` | Controls whether the radial menu is initially open and interactive. When `false`, input handling and visual updates are paused. `gap` | `number` | `0` | Defines the spacing between adjacent slices of the menu, expressed as a percentage of the radius. A larger value increases the visual separation between items. `selected` | `number` | `0` | The index of the initially selected item in the menu. `onChange` | `(id: string \| number) => void` | `undefined` | Callback triggered when a new item becomes selected. Returns either the item’s `id` (if defined) or its index. `onItemChanged` | `() => void` | `undefined` | Callback executed when the number or order of menu items changes (e.g., due to re-rendering or dynamic updates). `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the radial menu. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the radial menu’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#ref-api] ## Radial Menu: Ref API To interact with the `RadialMenu` programmatically, you can use the `RadialMenuRef` interface. This interface provides access to the component’s root element and exposes methods for controlling its state and selection. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the `radial menu`’s root HTML element, useful for direct DOM access or styling. #### Methods Method Name | Parameters | Return Value | Description `open` | None | `void` | Opens the `radial menu`, enabling input handling and rendering active selection states. `close` | None | `void` | Closes the `radial menu`, disabling input tracking and freezing the current selection. `opened` | None | `boolean` | Returns the current visibility state of the component. `changeGap` | `value: number` | `void` | Dynamically adjusts the spacing between slices, allowing smooth transitions or effects that depend on menu density. `selectByIndex` | `index: number` | `void` | Selects a menu item by its zero-based index. Triggers the `onChange` event if the selection changes. `selectByVector` | `x: number, y: number` | `void` | Selects a menu item based on normalized vector coordinates (range `-1` to `1`), useful for controller or joystick input. Includes an internal deadzone for stable selection. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#slots] ## Radial Menu: Slots (1/6) The `RadialMenu` component exposes multiple slots that allow you to customize its structure, visuals, and behavior: - **RadialMenu.Item** - Defines an individual slice (menu option) displayed around the wheel. - **RadialMenu.Selector** - Visual layer for the colored wedge of each item, representing its selected state. - **RadialMenu.Content** - Container for the central content of the menu (e.g., icons, labels, or contextual info). - **RadialMenu.Indicator** - Represents the rotating half-arc that highlights the currently selected item or follows cursor/controller movement. - **RadialMenu.Icon** - Optional element positioned at the center of the `Indicator`, can be used to display an icon or pointer. #### RadialMenu.Item The `RadialMenu.Item` slot defines a single slice (menu option) within the radial menu. Each `RadialMenu.Item` you render creates **one slice** in the wheel. ##### Usage ```tsx
``` ##### Internal structure (advanced) --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#slots] ## Radial Menu: Slots (2/6) Structurally, each item in the `RadialMenu` starts as a square element with a `border-radius` of `50%`, effectively turning it into a circle.\ The circular shape is then divided into slices using the CSS `clip-path` property. Each item is clipped to a specific wedge size, determined by the total number of items in the menu.\ Once clipped, the slices are evenly rotated around the center, forming the complete radial layout. Internally, each `RadialMenu.Item` is composed of three layers that work together to form the visual and interactive slice of the menu: - **Selector** - the colored wedge behind the item’s content, visually representing its active or selected state. - **Content** - the user-provided content inside the slot (e.g., an icon or label). It remains visually upright through counter-rotation, even as the menu spins. - **Wrapper** - the outer container that holds the elements. It manages spacing, transforms, and event handling for the item. **Tip:** In most cases, you only need to place an image, icon, or any content inside the `RadialMenu.Item` slot — everything else is handled automatically.\ However, if you plan to create a fully custom look or integrate the radial layout into a unique design system, understanding how the component’s internal structure works will help you modify it confidently. ##### Props --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#slots] ## Radial Menu: Slots (3/6) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to the item’s outer wrapper. `style-selected` | `JSX.CSSProperties` | `{}` | Inline styles applied to the item’s outer wrapper **only when this item is selected**. Useful for scale, glow, or emphasis effects. `class` | `string` | `""` | Additional CSS classes applied to the item’s outer wrapper. `class-selected` | `string` | `""` | Additional CSS classes applied to the item’s outer wrapper **only when this item is selected**. `id` | `string` | `undefined` | Stable identifier emitted by `onChange`. If omitted, the item’s index is used. `offset` | `string` | `1vmax` | Optional vertical padding (CSS size) that nudges the item’s content toward/away from the ring (e.g., `"1vmax"`). #### RadialMenu.Selector The `RadialMenu.Selector` slot defines the **colored wedge** of each `RadialMenu.Item`.\ It serves as the visual slice that fills the area behind the item’s content and represents its active or selected state. ##### Usage The `Selector` slot is the main way to customize the **appearance and size** of each slice.\ Adjusting the selector’s `border-width` controls how thick each wedge appears, while the `border-color` defines the base color of that slice.\ By providing a `style-selected` or `class-selected`, you can also control how the selected item visually changes when active. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#slots] ## Radial Menu: Slots (4/6) ```tsx {/* Items */} ``` ##### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied directly to the selector wedge. Used to define the base look of each slice. `style-selected` | `JSX.CSSProperties` | `{}` | Inline styles applied when the parent item is selected. Use this to visually distinguish the active slice. `class` | `string` | `""` | Additional CSS classes applied to the selector wedge. Used to define the base look of each slice. `class-selected` | `string` | `""` | CSS classes applied when the parent item is selected. Use this to visually distinguish the active slice. #### RadialMenu.Content The `RadialMenu.Content` slot represents the **inner area** of the radial menu — the circular space at its center.\ It’s primarily used to display any content that should remain static and upright while the outer slices rotate, such as icons, labels, player stats, or contextual information. You can place any custom content inside the `RadialMenu.Content` slot.\ This slot remains fixed in the center and doesn’t rotate along with the slices. ```tsx

Weapons

Current weapon info
{/* Items */}
``` ##### Props --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#slots] ## Radial Menu: Slots (5/6) Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied directly to the content container. `class` | `string` | `""` | Additional CSS classes applied to the content container. #### RadialMenu.Indicator The `RadialMenu.Indicator` is an optional slot that represents the **rotating arc** or **marker** that follows the current selection around the menu.\ It visually indicates which slice is active or which direction the user is pointing toward (for example, when using a joystick or mouse). This slot can also contain an optional `RadialMenu.Indicator.Icon`, which stays attached to the indicator’s center and rotates alongside it. ##### Usage To display the indicator simply provide it inside the `RadialMenu` component. ```tsx {/* Items */} ``` ##### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to the indicator arc. `class` | `string` | `""` | Additional CSS classes applied to the indicator arc. #### RadialMenu.Icon The `RadialMenu.Icon` slot is an **optional element** that appears at the center of the `RadialMenu.Indicator`.\ It’s used to visually represent the pointer or direction of the active slice. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#slots] ## Radial Menu: Slots (6/6) If you **don’t provide any children** inside the slot, a **default arrow-shaped placeholder** will be rendered automatically.\ This placeholder can be fully customized through the slot’s `style` and `class` props.\ If you **do provide content** (e.g., an image or SVG), it will **override the default icon** and render your custom content instead. ##### Usage ```tsx ``` **Caution:** When you provide a custom icon, all **default styles** of the `RadialMenu.Icon` slot are overridden.\ This means you may need to manually define its dimensions or layout styles — for example, setting explicit `width` and `height` — if your custom image doesn’t appear as expected. ##### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied directly to the icon or placeholder element. `class` | `string` | `""` | Additional CSS classes applied to the icon or placeholder element. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#guide] ## Radial Menu: Guide (1/13) #### Customizing the Selected Item You can customize the look of the **selected item** through the `class-selected` and `style-selected` props of either the `RadialMenu.Selector` or the `RadialMenu.Item` slots — depending on what you want to modify. - To **change the highlight or color** of the selected slice, customize the `RadialMenu.Selector`. - To **alter the appearance of the entire item** (e.g., scale, glow, border), customize the `RadialMenu.Item`. In the following example, the selected item grows slightly larger when selected, and the highlight color changes to a custom shade of blue. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#guide] ## Radial Menu: Guide (2/13) ```tsx // Assets import import Weapon1 from "@assets/wheel/weapon1.png"; import Weapon2 from "@assets/wheel/weapon2.png"; import Weapon3 from "@assets/wheel/weapon3.png"; import Weapon4 from "@assets/wheel/weapon4.png"; import Weapon5 from "@assets/wheel/weapon5.png"; import Weapon6 from "@assets/wheel/weapon6.png"; import Center from "@assets/wheel/GameMessage_AchievmentIcon.png"; import { For } from 'solid-js'; import RadialMenu from "@components/Complex/RadialMenu/RadialMenu"; import Image from "@components/Media/Image/Image"; const wheelItems = [ { id: "shotgun", img: Weapon1 }, { id: "pistol", img: Weapon2 }, { id: "rifle", img: Weapon3 }, { id: "sniper", img: Weapon4 }, { id: "smg", img: Weapon5 }, { id: "grenade", img: Weapon6 }, ] const App = () => { return ( {(item) => (
)}
); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#guide] ## Radial Menu: Guide (3/13) **Tip:** To customize the appearance of items **when they’re not selected**, simply apply regular `class` or `style` props to the `RadialMenu.Selector`.\ These define the default look of each slice before a selection occurs. #### Reacting to Item Changes To handle item selection changes in the `RadialMenu`, use the `onChange` prop.\ This prop accepts a callback function that receives the `id` of the newly selected item as its argument. ##### Displaying the Selected Item in the Center In the following example, we store the currently selected item in a `signal` and update it whenever the user changes their selection.\ The `id` of the selected item is then displayed inside the `RadialMenu.Content` slot. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#guide] ## Radial Menu: Guide (4/13) ```tsx // Assets import import Weapon1 from "@assets/wheel/weapon1.png"; import Weapon2 from "@assets/wheel/weapon2.png"; import Weapon3 from "@assets/wheel/weapon3.png"; import Weapon4 from "@assets/wheel/weapon4.png"; import Weapon5 from "@assets/wheel/weapon5.png"; import Weapon6 from "@assets/wheel/weapon6.png"; import Center from "@assets/wheel/GameMessage_AchievmentIcon.png"; import { For } from 'solid-js'; import RadialMenu from "@components/Complex/RadialMenu/RadialMenu"; import Image from "@components/Media/Image/Image"; const wheelItems = [ { id: "shotgun", img: Weapon1 }, { id: "pistol", img: Weapon2 }, { id: "rifle", img: Weapon3 }, { id: "sniper", img: Weapon4 }, { id: "smg", img: Weapon5 }, { id: "grenade", img: Weapon6 }, ] const App = () => { const [currentItem, setCurrentItem] = createSignal(wheelItems[0]); return ( setCurrentItem(id)}>
{`Selected item: ${currentItem()}`}
{(item) => (
)}
); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#guide] ## Radial Menu: Guide (5/13) #### Alternative Selection Methods (programmatic selection) When the `RadialMenu` is open, it automatically reacts to `mousemove` events and continuously tracks the cursor position until it’s closed. Beyond this default behavior, items can also be selected programmatically in two additional ways: - Using the `selectByIndex` method from the component’s `ref`, providing a valid item index. - Using the `selectByVector` method from the component’s `ref`, providing normalized X and Y values (ranging from -1 to 1). This approach is ideal for mapping to a gamepad stick. ##### Selecting an item by index To select an item by its index: 1. Declare a variable and assign it the `RadialMenuRef` type. 2. Pass that variable to the `ref` prop of the `RadialMenu` component. 3. Call `ref.selectByIndex()` and provide a valid index as the argument. In the following example, pressing the keys **1-6** on the keyboard will select the corresponding item in the `RadialMenu`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#guide] ## Radial Menu: Guide (6/13) ```tsx // Assets import import Weapon1 from "@assets/wheel/weapon1.png"; import Weapon2 from "@assets/wheel/weapon2.png"; import Weapon3 from "@assets/wheel/weapon3.png"; import Weapon4 from "@assets/wheel/weapon4.png"; import Weapon5 from "@assets/wheel/weapon5.png"; import Weapon6 from "@assets/wheel/weapon6.png"; import Center from "@assets/wheel/GameMessage_AchievmentIcon.png"; import { For, onCleanup, onMount } from 'solid-js'; import Image from "@components/Media/Image/Image"; import RadialMenu, { RadialMenuRef } from "@components/Complex/RadialMenu/RadialMenu"; const wheelItems = [ { id: "shotgun", img: Weapon1 }, { id: "pistol", img: Weapon2 }, { id: "rifle", img: Weapon3 }, { id: "sniper", img: Weapon4 }, { id: "smg", img: Weapon5 }, { id: "grenade", img: Weapon6 }, ] const App = () => { let ref: RadialMenuRef; const handleKeyPress = (e: KeyboardEvent) => { if (e.key >= "1" && e.key <= "6") { const index = Number(e.key) - 1; // convert '1'..'6' to 0..5 ref!.selectByIndex(index); } } onMount(() => window.addEventListener("keydown", handleKeyPress)); onCleanup(() => window.removeEventListener("keydown", handleKeyPress)); return ( {(item) => (
)}
); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#guide] ## Radial Menu: Guide (7/13) ##### Selecting an item with gamepad stick (by vector) To select an item using a gamepad stick: 1. Declare a variable and assign it the `RadialMenuRef` type. 2. Pass that variable to the `ref` prop of the `RadialMenu` component. 3. Call `ref.selectByVector()` and provide valid `x` and `y` coordinates representing the stick direction. In the following example, each frame reads the coordinates of the **right stick** and passes them to the `RadialMenu` to change the active item dynamically. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#guide] ## Radial Menu: Guide (8/13) ```tsx // Assets import import Weapon1 from "@assets/wheel/weapon1.png"; import Weapon2 from "@assets/wheel/weapon2.png"; import Weapon3 from "@assets/wheel/weapon3.png"; import Weapon4 from "@assets/wheel/weapon4.png"; import Weapon5 from "@assets/wheel/weapon5.png"; import Weapon6 from "@assets/wheel/weapon6.png"; import Center from "@assets/wheel/GameMessage_AchievmentIcon.png"; import { For, onCleanup, onMount } from 'solid-js'; import Image from "@components/Media/Image/Image"; import RadialMenu, { RadialMenuRef } from "@components/Complex/RadialMenu/RadialMenu"; const wheelItems = [ { id: "shotgun", img: Weapon1 }, { id: "pistol", img: Weapon2 }, { id: "rifle", img: Weapon3 }, { id: "sniper", img: Weapon4 }, { id: "smg", img: Weapon5 }, { id: "grenade", img: Weapon6 }, ] const App = () => { let ref: RadialMenuRef; const updateGamepad = () => { const gp = navigator.getGamepads()[0]; if (gp) { const x = gp.axes[2]; // right stick X const y = gp.axes[3]; // right stick Y ref!.selectByVector(x, y); } requestAnimationFrame(updateGamepad); }; onMount(() => requestAnimationFrame(updateGamepad)); return ( {(item) => (
)}
); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#guide] ## Radial Menu: Guide (9/13) **Caution:** The `updateGamepad` function in this example is intended for demonstration purposes and is **not optimized for production use**.\ For robust and configurable gamepad integration, we recommend using our [Interaction Manager](https://frontend-tools.coherent-labs.com/interaction-manager/features/gamepad/) library. #### Opening and Closing the Menu To control the visibility of the `RadialMenu`, use the `open()` and `close()` methods from its `ref`.\ You can also use the `opened` signal provided by the component to check its current visibility state. In the following example, the menu is hidden by default and only opens while the **Shift** key is being held down. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#guide] ## Radial Menu: Guide (10/13) ```tsx import Weapon1 from "@assets/wheel/weapon1.png"; import Weapon2 from "@assets/wheel/weapon2.png"; import Weapon3 from "@assets/wheel/weapon3.png"; import Weapon4 from "@assets/wheel/weapon4.png"; import Weapon5 from "@assets/wheel/weapon5.png"; import Weapon6 from "@assets/wheel/weapon6.png"; import Center from "@assets/wheel/GameMessage_AchievmentIcon.png"; import { For } from 'solid-js'; import RadialMenu, {RadialMenuRef} from "@components/Complex/RadialMenu/RadialMenu"; import Image from "@components/Media/Image/Image"; const wheelItems = [ { id: "shotgun", img: Weapon1 }, { id: "pistol", img: Weapon2 }, { id: "rifle", img: Weapon3 }, { id: "sniper", img: Weapon4 }, { id: "smg", img: Weapon5 }, { id: "grenade", img: Weapon6 }, ] const App = () => { let ref: RadialMenuRef; const handleKeyDown = (e: KeyboardEvent) => { if (e.keyCode === 16 && !(ref!.opened())) ref!.open(); setPressedKey(e.code); } const handleKeyUp = (e: KeyboardEvent) => { if (e.keyCode === 16 && ref!.opened()) ref!.close(); setPressedKey(e.code); } return ( {(item) => (
)}
); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#guide] ## Radial Menu: Guide (11/13) #### Extending the RadialMenu With Navigation 2.0.0 The `RadialMenu` component integrates seamlessly with the `Navigation` system to create an intuitive keyboard and gamepad experience. The following example demonstrates an alternative, more robust approach to the selecting an item with gamepad stick guide and opening and closing the menu guide guides. We will use the `Navigation` component’s actions system to: 1. Open/close the menu using the SHIFT key (Keyboard) or LB button (Gamepad). 2. Use the right joystick for item selection. 3. Optimize performance by pausing input listeners when the menu is hidden. ##### Implementation Steps 1. Make sure the `RadialMenu` is a descendant of a `Navigation` component in your component tree. 2. Create custom set of actions for opening/closing the menu and selecting items. 3. Pass the actions to the `Navigation` component via the `actions` prop. 4. Use `resumeAction` and `pauseAction` to manage the joystick polling state. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#guide] ## Radial Menu: Guide (12/13) ```tsx import RadialMenu, { RadialMenuRef } from '@components/Complex/RadialMenu/RadialMenu'; import Navigation, { NavigationRef } from '@components/Utility/Navigation/Navigation'; import { ActionMap } from '@components/Utility/Navigation/types'; const HUD = () => { let navigationRef!: NavigationRef; let radialMenuRef!: RadialMenuRef; const openRadialMenu = () => { if (radialMenuRef?.opened()) return; radialMenuRef?.open(); navigationRef.resumeAction('radial-menu-select') } const closeRadialMenu = () => { radialMenuRef?.close(); navigationRef.pauseAction('radial-menu-select') } const selectRadialMenuOptions = (scope = '', [x, y]: [number, number]) => { radialMenuRef?.selectByVector(x, y) } const customActions: ActionMap = { 'open-radial-menu': { key: {binds: ['SHIFT'], type: ['press']}, button: {binds: ['left-shoulder'], type: 'hold'}, callback: openRadialMenu, }, 'close-radial-menu': { key: {binds: ['SHIFT'], type: ['lift']}, button: {binds: ['left-shoulder'], type: 'press'}, callback: closeRadialMenu, }, 'radial-menu-select': { button: {binds: ['right.joystick']}, callback: selectRadialMenuOptions, paused: true, // Start paused to avoid unnecessary calculations } }; return (
{/* RadialMenu content */}
) } ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/radial-menu/#guide] ## Radial Menu: Guide (13/13) ##### Few things to note - **The Release Mechanic**: To handle gamepad button releases, we use `hold` to open and `press` to close. While it may seem counter-intuitive, the `press` type fires specifically when the button is released after being held, ensuring the menu stays visible exactly as long as the user maintains pressure on the shoulder button. - **Performance Optimization**: Since gamepad joysticks are polled very frequently, the `radial-menu-select` action is marked as `paused: true` by default. We only resume it while the menu is active to eliminate unnecessary logic overhead when its not used. **Caution:** If your project already utilizes the `Navigation` system for UI focus and inputs, it is highly recommended to use this action-based approach rather than manual event listeners to maintain a single source of truth for input handling. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/] ## Tutorial The `Tutorial` component provides a declarative way to build guided walkthroughs directly inside your UI. Each `Tutorial.Step` wraps real elements, highlights them, and displays a tooltip with title and content, creating a structured onboarding or feature tour. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#installation] ## Tutorial: Installation Every component ships with the boilerplate. If you are working in your own project, add `Tutorial` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Tutorial ``` The CLI pulls in whatever `Tutorial` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#usage] ## Tutorial: Usage (1/2) To use the Tutorial component, wrap your existing UI with it and wrap every element you wish to be part of the tutorial with the `Tutorial.Step` component and provide it with an `order` prop. **Note:** For detailed usage instructions, examples, and customization options, refer to the Guide section. **Tip:** Check out [our blog post](https://coherent-labs.com/blog/uitutorials/gamefaceui-menu-tutorial/) to see how we used the `Tutorial` component to build an interactive walkthrough for our Menu UI. **index.tsx:** --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#usage] ## Tutorial: Usage (2/2) ```tsx import Tutorial, {TutorialRef} from "@components/Complex/Tutorial/Tutorial"; import Flex from "@components/Layout/Flex/Flex"; const App = () => { let ref!: TutorialRef; return ( ); }; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#api] ## Tutorial: API #### Tutorial Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the radial menu’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the radial menu’s root element. `ref` | `TutorialRef` \| `undefined` | `undefined` | A reference to the component, providing access to its methods and the underlying HTML element. `outset` | `number` | `0` | Extra offset (in px) applied between the tooltip/highlight and the target element. Useful when the target has shadows/borders or sits inside tight layouts. `tooltip` | `TooltipType` | `undefined` | Custom tooltip component to render instead of the default one. Receives the provided tutorial props (title, content, step, controls). `onChange` | `(step: number) => void` | `undefined` | Fired whenever the active tutorial step changes. The callback receives the **1-based** step index. `onStart` | `() => void` | `undefined` | Fired whenever the tutorial starts. `onEnd` | `() => void` | `undefined` | Fired whenever the tutorial ends. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the tutorial. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the tutorial’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#ref-api] ## Tutorial: Ref API To interact with the `Tutorial` programmatically, you can use the `TutorialRef` interface. This interface provides access to the component’s root element and exposes methods for controlling its state and selection. #### Properties Property | Type | Description `element` | `HTMLDivElement` | Root element of the tutorial wrapper. `progress` | `Accessor` | Current progress in `%` (0-100). Use it to display custom progress UIs. `current` | `Accessor` | Current active step (1-based). Returns `0` when the tutorial is not running. `target` | `Accessor` | The DOM element currently being highlighted. Useful if you need any specific information about the position or dimensions of the element #### Methods Method | Parameters | Return value | Description `tour` | `(step?: number)` | `void` | Starts the tutorial. If a step is provided, starts from that step instead of the first one. `exit` | — | `void` | Stops the tutorial and clears the active step. `next` | — | `void` | Moves to the next step, if any. `previous` | — | `void` | Moves to the previous step, if any. `pause` | — | `void` | Pauses the tutorial. `resume` | `(next?: boolean)` | `void` | Resumes a paused tutorial. If `next` is `true`, it will advance to the next step on resume (useful for interactive steps). `changeStep` | `(step: number)` | `void` | Jumps directly to the provided step (1-based). Use this when the tutorial should react to external UI events. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#slotscomponents] ## Tutorial: Slots/Components (1/4) The `Tutorial` component exposes: - **Tutorial.Step** - defines one step of the tutorial and marks the wrapped UI as the current target. - **Custom Tooltip** (via tooltip prop) - lets you fully replace the default tooltip UI. #### Tutorial.Step Wraps the element you want to highlight and registers it in the tutorial flow. ##### Usage Simply wrap the target element with `Tutorial.Step` and provide the required `order` prop. Providing `title` and `content` will display them in the tooltip for this step. ```tsx ``` **Caution:** Make sure to provide unique `order` values for each step. The tutorial will follow the ascending order of these values. **Caution:** If a step is repeated, it may cause unexpected behavior. ##### Props Prop Name | Type | Default | Description `order` | `number` | — | Required. Controls the order in which the step is shown. `title` | `string` \| `undefined` | "" | Tooltip title. If omitted, an empty string is used for the step. `content` | `string` \| `undefined` | "" | Tooltip content. If omitted, an empty string is used for the step. `outset` | `number` | 0 | Per-step offset. Overrides the `Tutorial`’s `outset` for this step only. `position` | `top` \| `left` \| `right` \| `bottom` | `auto` | Tooltip placement relative to the target. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#slotscomponents] ## Tutorial: Slots/Components (2/4) #### Custom Tooltip You can replace the default tooltip by passing a tooltip prop to `Tutorial`. This prop accepts a **custom component** or a **function that returns JSX**, allowing you to fully control the tooltip’s layout, animations, and controls. ##### Provided props Prop Name | Type | Description `title` | `string` \| `undefined` | The current step’s title. Falls back to `''` if omitted. `content` | `string` \| `JSX.Element` \| `undefined` | The tooltip’s main content. Falls back to `''` if omitted. `step` | `Accessor` | The current **1-based** step index. `progress` | `Accessor` | Current tutorial progress (0-100). Useful for showing a progress bar. `Next` | `Component` | Prebuilt “Next” button component. When clicked on the final step, it ends the tutorial. `Prev` | `Component` | Prebuilt “Previous” button component. Navigates back one step. ##### Usage To declare a custom tooltip, you need to follow these steps: 1. Create a component typed as `TooltipType` (you need to import the type) 2. Pass it to the `tooltip` prop of the `Tutorial` component 3. Use the provided props (`title`, `content`, `step`, `progress`, `Next`, `Prev`) to build your layout and behavior. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#slotscomponents] ## Tutorial: Slots/Components (3/4) ```tsx import Tutorial, {TutorialRef} from "@components/Complex/Tutorial/Tutorial"; import { TooltipType } from "@components/Complex/Tutorial/TutorialTooltip"; import Progress from "@components/Feedback/Progress/Progress"; import Flex from "@components/Layout/Flex/Flex"; const MyTooltip: TooltipType = (props) => { return (
{props.title}
{props.content}
Previous Next
) } const App = () => { let ref!: TutorialRef; return ( ); }; export default App; ``` Optionally, you can extend the `TooltipType` to pass **additional custom props** to your `tooltip` component. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#slotscomponents] ## Tutorial: Slots/Components (4/4) ```tsx interface CustomTooltipProps { customLabel: string; } const MyTooltip: TooltipType = (props) => { return (
{props.title}
{props.content}
Previous Next
{props.customLabel}
) } const App = () => { return ( }> {/* ... */} ); }; export default App; ``` **Caution:** When passing additional props, you must provide the tooltip as a callback function that returns your component. This ensures both the built-in tutorial props and your custom ones are passed correctly. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#guide] ## Tutorial: Guide (1/12) **Note:** Working with the Tutorial component requires understanding how to use access the component’s refs. Checkout the following guide to learn more. #### Controlling the tutorial programmatically You can start, pause, stop, and navigate the tutorial using the `TutorialRef` methods. ##### Starting the tutorial The tutorial can be started programmatically using the `tour()` method from the `TutorialRef`. ```tsx import Tutorial, {TutorialRef} from "@components/Complex/Tutorial/Tutorial"; const App = () => { let ref!: TutorialRef; return ( <> {/* Steps go here */} ); }; ``` ##### Pausing and resuming the tutorial You can pause the tutorial at any time using the `pause()` method, and resume it later with the `resume()` method. This behavior is useful for interactive steps where user input is required. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#guide] ## Tutorial: Guide (2/12) ```tsx import Tutorial, {TutorialRef} from "@components/Complex/Tutorial/Tutorial"; const App = () => { let ref!: TutorialRef; const handleUserInteraction = () => { if (ref.current() === 0) return; // Tutorial not running if (ref.current() === 3) { // pause on step 3 ref.pause(); // Do something... setTimeout(() => { // Resume after 2 seconds ref.resume(); }, 2000); } }; return ( <>
{/* Steps go here */}
); }; ``` **Tip:** When resuming, you can pass `true` to the `resume()` method to automatically advance to the next step. ##### Concluding the tutorial You can end the tutorial manually at any time using the `exit()` method from the `TutorialRef`. ```tsx import Tutorial, {TutorialRef} from "@components/Complex/Tutorial/Tutorial"; const App = () => { let ref!: TutorialRef; const handleUserInteraction = () => { if (ref.current() === 0) return; // Tutorial not running if (ref.current() === 3 && someCondition) { ref.end(); } }; return ( <>
{/* Steps go here */}
); }; ``` #### Reacting to step changes --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#guide] ## Tutorial: Guide (3/12) You can use the `onChange` prop to react to step changes in the tutorial. This is useful if additional logic is needed between certain steps. ```tsx import Tutorial, {TutorialRef} from "@components/Complex/Tutorial/Tutorial"; const App = () => { let ref!: TutorialRef; const handleStepChange = (step: number) => { if (step === 2) { console.log("User reached step 2, showing modal..."); // Show a modal or perform other actions } if (step === 4) { ref.pause(); console.log("Tutorial paused at step 4 for user interaction."); } }; return ( <> {/* Steps go here */} ); }; ``` #### Per step customization You can customize individual steps of the tutorial by using the `outset` and `position` props on the `Tutorial.Step` component. This allows for fine-tuning the tooltip’s placement and offset for specific steps. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#guide] ## Tutorial: Guide (4/12) ```tsx import Tutorial, {TutorialRef} from "@components/Complex/Tutorial/Tutorial"; const App = () => { let ref!: TutorialRef; return ( <> ); }; export default App; ``` **Tip:** The `outset` also accept negative values, allowing you to “shrink” the highlight rectangle around the target element. #### Customizing your tooltip’s behavior (Examples) You can replace the default tooltip by passing a tooltip prop to `Tutorial`. The component you provide will receive several props to help you build your custom layout and behavior. ##### Manually placing the tooltip for specific steps Sometimes, you may want to adjust the tooltip’s position for a particular step. You can do this by checking the current step and applying classes or inline styles that offset the tooltip as needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#guide] ## Tutorial: Guide (5/12) ```tsx import Tutorial, {TutorialRef} from "@components/Complex/Tutorial/Tutorial"; import { TooltipType } from "@components/Complex/Tutorial/TutorialTooltip"; import Flex from "@components/Layout/Flex/Flex"; const MyTooltip: TooltipType = (props) => { return (
{props.title}
{props.content}
Previous Next
) } const App = () => { return ( { /* Steps go here */ } ); }; export default App; ``` **Note:** In this example, the tooltip is positioned relative to its own wrapper, which already defines its base placement on the screen. ##### Changing the next button’s content for the last step You can customize your tooltip with the custom provided props to change the “Next” button’s content on the final step. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#guide] ## Tutorial: Guide (6/12) ```tsx import Tutorial, {TutorialRef} from "@components/Complex/Tutorial/Tutorial"; import { TooltipType } from "@components/Complex/Tutorial/TutorialTooltip"; import Flex from "@components/Layout/Flex/Flex"; const MyTooltip: TooltipType = (props) => { return (
{props.title}
{props.content}
Previous {props.progress() === 100 ? 'Done' : 'Next' }
) } const App = () => { return ( { /* Steps go here */ } ); }; export default App; ``` ##### Applying conditional classes to control button visibility You can conditionally apply classes and styles to the provided `Next` and `Prev` components to control their visibility based on the current step. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#guide] ## Tutorial: Guide (7/12) ```tsx import Tutorial, {TutorialRef} from "@components/Complex/Tutorial/Tutorial"; import { TooltipType } from "@components/Complex/Tutorial/TutorialTooltip"; import Flex from "@components/Layout/Flex/Flex"; const MyTooltip: TooltipType = (props) => { return (
{props.title}
{props.content}
Previous Next
) } const App = () => { return ( { /* Steps go here */ } ); }; export default App; ``` #### Extending the Tutorial With Navigation 2.0.0 Integrating it with the `Navigation` system allows players to progress using gamepad buttons and enables the tutorial to react dynamically to game state changes. We will cover two scenarios for using the `Navigation` system with the `Tutorial` component: ##### 1. Standard Button Navigation Most tutorials allow the player to move to the next step using the “primary” button. We can map the `Next` and `Prev` buttons so the player doesn’t have to use a mouse to navigate through the tutorial. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#guide] ## Tutorial: Guide (8/12) We can bind the “Enter” key and the gamepad “A” button to the `Next` action, and the “Backspace” key and the gamepad “B” button to the `Previous` action. Additionally, we can bind the “Escape” key and the gamepad “Y” button to an `Exit` action that ends the tutorial immediately. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#guide] ## Tutorial: Guide (9/12) ```tsx import Navigation from '@components/Utility/Navigation/Navigation'; import { ActionMap } from '@components/Utility/Navigation/types'; import Tutorial, { TutorialRef } from '@components/Complex/Tutorial/Tutorial'; const App = () => { // Declare tutorial ref to gain access to the component's methods let tutorialRef!: TutorialRef; // Define custom actions for tutorial navigation const customActions: ActionMap = { 'tutorial-next': { // Map 'Enter' or Gamepad 'A' to advance key: { binds: ['ENTER'], type: ['press'] }, button: { binds: ['face-button-down'], type: 'press' }, callback: () => { if (tutorialRef.current() === 0) { tutorialRef.tour(); return; } else if (tutorialRef.progress() === 100) { tutorialRef.exit(); return; } tutorialRef.next() } }, 'tutorial-prev': { key: {binds: ['BACKSPACE'], type: ['press', 'hold']}, button: {binds: ['face-button-right'], type: 'press'}, callback: () => tutorialRef.previous() }, 'end-tutorial': { key: {binds: ['ESC'], type: ['press', 'hold']}, button: {binds: ['face-button-top'], type: 'press'}, callback: () => tutorialRef.exit() } }; return ( // Pass actions and attach ref to the Tutorial component {/* Steps */} ); }; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#guide] ## Tutorial: Guide (10/12) **Handling Input Conflicts:** If you have keys or buttons that are used for other actions in your UI, you can use the `pauseAction` method from the `Navigation` component to pause the actions that have key/button conflicts while the tutorial is active, and resume them when it’s not. This way you can ensure that the tutorial navigation doesn’t interfere with other interactions in your UI. You can see an example of how to pause and resume actions in the Navigation documentation. **Default Actions:** Alternatively, you can use the default `select` and `back` actions provided by the `Navigation` system, which are already mapped to common keys and buttons. In such case you will need to make sure that the `tutorialRef.element` is focused when the tutorial starts to ensure the actions are triggered correctly. ##### 2. Interactive Steps Sometimes you don’t want the player to just click “Next”; you want them to perform an action (e.g., “Open the Inventory”). In this case, you can `pause()` the tutorial and use a `Navigation` action to `resume()` it. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#guide] ## Tutorial: Guide (11/12) ```tsx import Navigation, { NavigationRef } from '@components/Utility/Navigation/Navigation'; import { ActionMap } from '@components/Utility/Navigation/types'; import Tutorial, { TutorialRef } from '@components/Complex/Tutorial/Tutorial'; const InventoryTutorial = () => { // Declare refs for both Tutorial and Navigation components let tutorialRef!: TutorialRef; let navigationRef!: NavigationRef; // Provide a signal for showing the inventory step const [inventoryOpened, setInventoryOpened] = createSignal(false); // Define a method that will add the custom action to open inventory const addCustomAction = () => { navigationRef.addAction('open-inventory', { key: { binds: ['I'], type: ['press'] }, button: { binds: ['playstation.options'], type: 'press' }, callback: onTutorialInventoryOpen }) } // Define a method that will remove the custom action once it's used const removeCustomAction = () => { navigationRef.removeAction('open-inventory'); } // When the inventory is opened, resume the tutorial, move to the next step and remove the action. const onTutorialInventoryOpen = () => { setInventoryOpened(true); tutorialRef.resume(true); // resume and move to next step removeCustomAction(); }; return ( { /* When reaching the inventory step, add the custom action and pause the tutorial */} { if (step === 2) { addCustomAction(); setTimeout(() => tutorialRef.pause(), 2000) } }}>
{ /* Wrap the inventory with a signal to make it able to be shown/hidden */}
); }; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/complex/tutorial/#guide] ## Tutorial: Guide (12/12) In this example, when the user reaches step 2 of the tutorial, a custom action “open-inventory” is added to the `Navigation` system, allowing the user to open the inventory by pressing “I” or the corresponding gamepad button. The tutorial is paused to wait for the user’s interaction. Once the inventory is opened, the tutorial resumes and advances to the next step, while the custom action is removed to prevent further triggers. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-area/] ## Chart Area The `Chart.Area` component fills the region of a `Chart.Line` down to the baseline. All Line features — curves, gaps, hovering, axes, and legend — apply unchanged. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-area/#basic-usage] ## Chart Area: Basic Usage **index.tsx:** ```tsx import Chart from '@components/Feedback/Chart/Chart'; import { createSignal } from 'solid-js'; const App = () => { const [load] = createSignal([ { label: 'Player', points: [ { type: 'strength', value: 13 }, { type: 'agility', value: 9 }, { type: 'stamina', value: 16 }, ], }, ]); return ( ); }; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-area/#options] ## Chart Area: Options #### Overlapping vs. Stacked By default, series **overlap** with translucent fills (0.25 opacity) so overlapping areas remain visible. Each area keeps a full-strength outline for clarity. For stacked areas where series sit on top of each other: ```tsx ``` **Note:** Use `stacked` only when values sum to a meaningful total. Stacked areas make individual series hard to compare since only the bottom sits on a baseline. Prefer overlapping areas or line charts for comparison. #### Remove Outline ```tsx ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-area/#api] ## Chart Area: API #### Props Inherits all `Chart.Line` props, plus: Prop | Type | Default | Description `stacked` | `boolean` | `false` | Stack series instead of overlapping. #### Slots ##### Chart.Area.Fill Prop | Type | Default | Description `class` | `string` | `""` | CSS classes for filled regions. `style` | `JSX.CSSProperties` | `{}` | Inline styles for filled regions. `opacity` | `number` | `0.25` | Fill opacity (increase when series don’t overlap). `curve` | `CurveType` | inherits | Override chart’s curve. ##### Chart.Area.Stroke Same props as `Chart.Line.Stroke`. Set `width={0}` to remove outline. ##### Chart.Area.Point Same props as `Chart.Line.Point`. ##### Shared Slots `Chart.XAxis`, `Chart.YAxis`, `Chart.Grid`, `Chart.Legend`, `Chart.Tooltip`, `Chart.Labels` — see Shared slots. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-bar/] ## Chart Bar The `Chart.Bar` component compares values across categories and series. It supports axes, gridlines, legend, tooltips, and label slots. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-bar/#basic-usage] ## Chart Bar: Basic usage (1/3) Each item in `data` is a series, and each point is one category. When multiple series share the same categories, the chart becomes grouped by default. **index.tsx:** ```tsx import Chart from '@components/Feedback/Chart/Chart'; import { createSignal } from 'solid-js'; const App = () => { const [stats] = createSignal([ { label: 'Player', points: [ { type: 'strength', value: 13 }, { type: 'agility', value: 9 }, { type: 'stamina', value: 16 }, ], }, { label: 'Enemy', points: [ { type: 'strength', value: 7 }, { type: 'agility', value: 18 }, { type: 'stamina', value: 11 }, ], }, ]); return ( ); }; ``` **Caution:** The chart fills its container, so the container must have a defined size. Axis labels sit in the margin, so small containers have less room for bars. #### Layout and orientation ```tsx ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-bar/#basic-usage] ## Chart Bar: Basic usage (2/3) Prop | Values | Effect `layout` | `'grouped'` (default) | Each series gets its own bar beside the others in the same category. - | `'stacked'` | Series accumulate. Positive values stack upward from zero and negative values stack downward, so a mixed stack does not cancel itself into a misleading total. `orientation` | `'vertical'` (default) | Categories run along the bottom, values rise up the side. - | `'horizontal'` | Categories run down the side, values extend along the bottom. This is useful when category labels are long. Stacked segments keep a 2px gap in the surface color, which helps similar hues stay distinct where they meet. Only the outermost segment of a stack is rounded. #### Baseline and negative values The value domain always includes zero, and bars grow from that baseline. A negative value simply grows in the opposite direction and is rounded at its far end. ```tsx // domain becomes roughly [-10, 10]; the baseline sits mid-plot ``` Use a fixed domain when you need a consistent scale across multiple charts: ```tsx ``` By default the computed domain is rounded outward so tick values stay readable. For example, a maximum of 18 typically becomes an axis ending at 20. Set `nice={false}` to keep the exact extent instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-bar/#basic-usage] ## Chart Bar: Basic usage (3/3) **Note:** There is intentionally no secondary axis. If two measures use different scales, they should either live in separate charts or be normalized to a common base. A dual-axis chart can imply correlation by shifting one scale against the other. #### Interactivity This behaves like the other chart types: interactivity is off by default, `interactive` turns it on, and `interactive="overlay"` swaps SVG hit testing for a single overlay that resolves the hovered bar mathematically. ```tsx inspect(e.series.label, e.point.type)}>
{e.series.label}: {e.point.value}
} />
``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-bar/#api] ## Chart Bar: API #### Props Takes the shared chart props, plus: Prop Name | Type | Default | Description `layout` | `'grouped' \| 'stacked'` | `'grouped'` | Whether series sit side by side or accumulate. `orientation` | `'vertical' \| 'horizontal'` | `'vertical'` | Which axis the categories run along. `domain` | `[number, number]` | computed | Fixes the minimum and maximum of the value axis instead of deriving them from the data. `nice` | `boolean` | `true` | Rounds the computed domain outward to readable tick values. See Types for the shared data and event types. #### Behaviour notes - **The legend lists series**, not categories. Clicking an entry hides that series, and the remaining series expand to fill the freed space. - **Missing categories** count as zero, so different series do not need to declare the same points. - **Bars are `` elements**, not ``. Gameface prefers path-based animation because attribute animation on primitives is less reliable, and a path also allows rounding only one end. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-bar/#slots] ## Chart Bar: Slots #### Chart.Bar.Fill Prop Name | Type | Default | Description `class` | `string` | `""` | CSS classes applied to every bar. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to every bar. `width` | `ChartLength` | band width | Bar thickness as a length or a share of its band (`'60%'`). `gap` | `ChartLength` | `0` | Gap between bars within a group. `groupGap` | `number` | `0.2` | Gap between category groups as a share of the band. `cornerRadius` | `ChartLength` | `'0.25rem'` | Rounds the data end. #### Chart.XAxis, Chart.YAxis, Chart.Grid, Chart.Legend, Chart.Tooltip, Chart.Labels Shared with other chart types. See Shared slots for their props. `YAxis` is the value axis on a vertical chart, and `XAxis` is the value axis on a horizontal one. `Chart.Labels` centers a value inside each bar, and `format` receives that bar’s point and series. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-donut/] ## Chart Donut A `Chart.Pie` with the middle cut out. Use the empty center to show a total, the selected value, or custom content. All pie features — data model, palette, animation, interactivity, legend, and tooltips — work the same way. This page only covers the donut-specific behavior. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-donut/#usage] ## Chart Donut: Usage (1/2) **index.tsx:** ```tsx import Chart from '@components/Feedback/Chart/Chart'; import { createSignal } from 'solid-js'; const App = () => { const [stats, setStats] = createSignal([ { label: 'Loadout', points: [ { type: 'strength', value: 13 }, { type: 'agility', value: 9 }, { type: 'stamina', value: 16 }, { type: 'intellect', value: 6 }, ], }, ]); return ( ); }; ``` #### The inner radius `innerRadius` accepts either a ratio of the outer radius or a pixel value. The default is `'60%'`. ```tsx {/* thicker ring */} {/* 48px */} ``` The value is clamped to `[0, outerRadius]`, so an oversized value flattens the ring instead of creating an inverted shape. An `innerRadius` of `0` behaves like a pie chart. **Note:** The hole is a real gap, not a decorative overlay. When the pointer is over the center, hit testing resolves to no slice in either mode, so a tooltip does not follow the pointer across the middle of the chart. #### Filling the hole There are two ways to populate the center, and they can be combined. **`Chart.Labels placement="hole"`** renders a derived value: the total of the visible slices, or the hovered slice’s value and label while the pointer is on the ring. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-donut/#usage] ## Chart Donut: Usage (2/2) ```tsx `${point.value} pts`} /> ``` **`Chart.Donut.Hole`** takes over the center completely. Its children replace the derived label content. ```tsx ``` If you leave `Chart.Donut.Hole` empty, you can style the container while `Chart.Labels` supplies the content. The slot is the frame; the labels are what go inside it. ```tsx ``` The hole container matches the inner circle and has `pointer-events: none`, so anything inside it does not block hover interactions on the ring beneath it. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-donut/#api] ## Chart Donut: API #### Props Identical to `Chart.Pie`, plus: Prop Name | Type | Default | Description `innerRadius` | `ChartLength` | `'60%'` | Hole size as either a length (`'3rem'`) or a share of the outer radius (`'60%'`). Clamped to the outer radius. #### Behaviour notes - **The hole shows the total** of the visible slices. Hiding a slice from the legend removes it from the total. - **During animation**, the total is mid-tween, so it is displayed with one decimal place until it settles. - Everything else behaves the same as a pie: negatives are treated as zero, missing categories count as zero, and extra series are ignored. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-donut/#slots] ## Chart Donut: Slots #### Chart.Donut.Slice Prop Name | Type | Default | Description `class` | `string` | `""` | CSS classes applied to every slice. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to every slice. `padAngle` | `number` | `0` | Degrees of gap between slices. `cornerRadius` | `ChartLength` | `0` | Rounds the slice corners. `hoverOffset` | `ChartLength` | `0` | How far the hovered slice pops outward. Requires `interactive`. #### Chart.Donut.Hole Prop Name | Type | Default | Description `class` | `string` | `""` | CSS classes applied to the hole container. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to the hole container. `children` | `JSX.Element` | `undefined` | Content for the hole. Replaces anything `Chart.Labels placement="hole"` would render. #### Chart.Legend, Chart.Tooltip, Chart.Labels Shared with every chart type. See Shared slots for their props. `Chart.Labels` supports the same placements as a pie, plus one more: `placement` | Effect `'hole'` | Renders the total, or the hovered slice’s value and label, in the middle of the ring. The slot’s `class` and `style` apply to the hole container. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-line/] ## Chart Line The `Chart.Line` component traces values across categories. It uses the same cartesian system as `Chart.Bar` — axes, gridlines, legend, and domain handling — but it behaves differently on hover. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-line/#usage] ## Chart Line: Usage (1/2) **index.tsx:** ```tsx import Chart from '@components/Feedback/Chart/Chart'; import { createSignal } from 'solid-js'; const App = () => { const [stats] = createSignal([ { label: 'Player', points: [ { type: 'strength', value: 13 }, { type: 'agility', value: 9 }, { type: 'stamina', value: 16 }, ], }, { label: 'Enemy', points: [ { type: 'strength', value: 7 }, { type: 'agility', value: 18 }, { type: 'stamina', value: 11 }, ], }, ]); return ( ); }; ``` Vertices sit at category centers, so a line drawn over the same data as a bar chart lands in the middle of each bar rather than on the boundary between categories. #### Curves ```tsx ``` Value | Shape `'linear'` (default) | Straight segments between vertices. `'smooth'` | A monotone curve that does not overshoot the values, so it never invents a peak that is not in the data. `'step'` | Holds each value and steps at the midpoint. `'step-before'` / `'step-after'` | Steps at the start or end of each interval. #### Gaps --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-line/#usage] ## Chart Line: Usage (2/2) A category that a series does not declare counts as zero by default, and the line runs straight through it. Set `connectNulls={false}` to treat it as missing instead, which breaks the line. ```tsx ``` **Caution:** An undeclared category with values on both sides breaks the line into two visible runs, but a declared point sitting alone between two gaps has no segment to draw and renders as nothing. Show markers with `` whenever your data is sparse. #### Hovering Line and area charts use `overlay` hit-testing by default instead of native SVG events. That is intentional: a 2px stroke is too small to target reliably, so the chart resolves the nearest vertex instead. The category comes from the pointer’s x position, and the series is whichever line is vertically closest. The tooltip then snaps to that vertex rather than following the pointer, which keeps the crosshair readable. ```tsx
{e.series.label}: {e.point.value}
} />
``` Passing `interactive="svg"` forces per-element hit-testing, but that asks people to hover a hairline. It is rarely the right choice for this chart type. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-line/#api] ## Chart Line: API #### Props Takes the shared chart props, plus: Prop Name | Type | Default | Description `curve` | `CurveType` | `'linear'` | Interpolation between vertices. `connectNulls` | `boolean` | `true` | Whether an undeclared category breaks the line. `domain` | `[number, number]` | computed | Fixes the minimum and maximum of the value axis instead of deriving them from the data. `nice` | `boolean` | `true` | Rounds the computed domain out to readable ticks. `interactive={true}` resolves to `'overlay'` here, and hover events fire for the nearest vertex. See Types for the shared data and event types. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-line/#slots] ## Chart Line: Slots #### Chart.Line.Stroke Prop Name | Type | Default | Description `class` | `string` | `""` | CSS classes applied to every line. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to every line. `width` | `ChartLength` | `'0.125rem'` | Stroke width. `curve` | `CurveType` | inherits `curve` | Overrides the chart’s curve. `dash` | `string` | `undefined` | SVG dash pattern, for example `'6 4'`. #### Chart.Line.Point Prop Name | Type | Default | Description `class` | `string` | `""` | CSS classes applied to every marker. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to every marker. `radius` | `ChartLength` | `'0.25rem'` | Marker radius. The default is the smallest that stays comfortable to read. `show` | `'always' \| 'hover' \| 'never'` | `'hover'` | When markers appear. Markers include a 2px surface-colored ring so that when two series cross, the points stay distinct instead of merging into one blob. #### Chart.XAxis, Chart.YAxis, Chart.Grid, Chart.Legend, Chart.Tooltip, Chart.Labels Shared with other chart types. See Shared slots for their props. `Chart.Labels` places a value just above each vertex. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-pie/] ## Chart Pie The `Chart.Pie` component renders a proportional breakdown of one value set as a circle of slices. It uses inline SVG for geometry and regular HTML for text, so labels, legends, and tooltips stay fully styleable. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-pie/#usage] ## Chart Pie: Usage (1/3) Give the chart a `data` array. Each item is a series, and each series holds the points to plot. A pie shows one series, so its points become the slices. `data` is reactive: feed it from a signal and the chart updates with it. **index.tsx:** ```tsx import Chart from '@components/Feedback/Chart/Chart'; import { createSignal } from 'solid-js'; const App = () => { const [stats, setStats] = createSignal([ { label: 'Loadout', points: [ { type: 'strength', value: 13 }, { type: 'agility', value: 9 }, { type: 'stamina', value: 16 }, { type: 'intellect', value: 6 }, ], }, ]); return ( ); }; ``` **Caution:** The chart fills its container, so the container must have a size. A `Chart.Pie` inside an element with no height renders nothing. #### Colours Each slice takes its colour from the built-in categorical palette, assigned by index. You can override that in three places: the full palette, a series color, or a point color. ```tsx // point.color ?? series.color ?? palette[index % palette.length] ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-pie/#usage] ## Chart Pie: Usage (2/3) The palette ships with eight colours, arranged so neighbouring slices stay distinguishable for colourblind viewers. Beyond eight slices the colours repeat, which makes them less reliable as identifiers. Prefer fewer slices or group the tail into an “other” entry. #### Animation Pass an `animation` object and the chart tweens between data sets. Without it, there is no animation and no per-frame work. ```tsx ``` Values are interpolated and the geometry is rebuilt each frame, so a slice that appears grows outward instead of popping in. If you change the data mid-animation, the chart continues from its current state instead of snapping back. #### Interactivity Interactivity is off by default. A chart with no `interactive` prop attaches no listeners and lets pointer input pass straight through to the game. Turn it on with `interactive`: ```tsx select(e.point.type)}>
{e.point.label}: {e.point.value}
} />
``` Value | Behaviour omitted / `false` | No listeners. The SVG is set to `pointer-events: none`. `true` | Native SVG pointer events on each slice. The hit area is the arc itself. `"svg"` | Forces native SVG pointer events. `"overlay"` | Resolves the hovered slice mathematically from a single transparent overlay. One listener handles all slices, and it does not depend on SVG hit-testing. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-pie/#usage] ## Chart Pie: Usage (3/3) **Caution:** Native SVG hit-testing requires Gameface 3.1.1 or newer. On older versions, use `interactive="overlay"`, which works on any version. It is also the better choice for very large datasets, since native mode attaches listeners per slice. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-pie/#api] ## Chart Pie: API #### Props Takes the shared chart props, plus: Prop Name | Type | Default | Description `startAngle` | `number` | `0` | Degrees, clockwise from 12 o’clock. `endAngle` | `number` | `360` | Degrees. Use with `startAngle` for a partial pie. `data` takes the usual `ChartSeries[]`, but a pie renders only the first series; each of its points is a slice. See Types for the shared data and event types. #### Behaviour notes - **Negative values** have no meaning in a pie. They are treated as `0`, and the slice is not drawn even though the category remains in the legend. - **Missing categories** count as `0` when one series declares a category that another does not. - **An all-zero or empty dataset** renders no slices instead of throwing an error. - **Extra series** are ignored. A pie draws only the first series. Use one chart per series. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-pie/#slots] ## Chart Pie: Slots #### Chart.Pie.Slice Styles the slice geometry. Prop Name | Type | Default | Description `class` | `string` | `""` | CSS classes applied to every slice. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to every slice. `padAngle` | `number` | `0` | Degrees of gap between slices. `cornerRadius` | `ChartLength` | `0` | Rounds the slice corners. `hoverOffset` | `ChartLength` | `0` | How far the hovered slice pops outward. Requires `interactive`. #### Chart.Legend, Chart.Tooltip, Chart.Labels Shared with every chart type. See Shared slots for their props. On a pie, the legend lists slices: hiding one allows the remaining slices to grow and fill the circle. ##### Outside labels and leader lines `Chart.Labels` uses `placement="inside"` by default, or `placement="outside"` on a pie. Thin neighbouring slices place labels at nearly the same angle, so outside labels are pushed apart vertically to avoid stacking on top of one another. Each half of the circle is spaced independently, so a label never moves to the wrong side. Once a label moves away from its slice, it becomes harder to tell which slice it belongs to. That is why `leaderLines` exists: the connector runs out along the slice radius, turns, and meets the label where it ended up. ```tsx ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-spider/] ## Chart Spider The `Chart.Spider` component plots several measures on separate axes radiating from a center and connects them into a shape. It is a good fit for stat comparisons, where the silhouette of a build matters more than the exact numbers. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-spider/#usage] ## Chart Spider: Usage (1/2) Each point becomes an axis, and each series becomes a shape. A spider needs at least three categories to enclose an area. **index.tsx:** ```tsx import Chart from '@components/Feedback/Chart/Chart'; import { createSignal } from 'solid-js'; const App = () => { const [stats] = createSignal([ { label: 'Player', points: [ { type: 'strength', value: 13 }, { type: 'agility', value: 9 }, { type: 'stamina', value: 16 }, { type: 'intellect', value: 6 }, { type: 'spirit', value: 11 }, ], }, ]); return ( ); }; ``` The first category sits at 12 o’clock, and the rest run clockwise. Rotate the whole chart with `startAngle` in degrees. #### Pinning the scale By default the outer ring is the largest value in the data, rounded outward to a readable number. That is usually not what you want for a stat display: a character with low values can still fill the entire web because the scale shrinks to fit them. `maxValue` pins the outer ring instead, so the shape has an absolute meaning: ```tsx ``` With a fixed scale, low values make a small shape and high values nearly fill the web, which makes separate charts easier to compare. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-spider/#usage] ## Chart Spider: Usage (2/2) #### The web and the axes Both are opt-in slots, just like `Chart.Grid` on a bar chart. Without `Chart.Spider.Web` there are no rings to read values against, and without `Chart.Spider.Axis` there are no spokes or category names. ```tsx ``` #### Hovering Like line and area charts, a spider defaults to `overlay` hit-testing. A series here is a single closed path spanning every category, so native SVG hit-testing can only answer “which series” — never “which point.” Instead, the nearest spoke picks the category, and the vertex nearest the pointer’s distance from the center picks the series. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-spider/#api] ## Chart Spider: API #### Props Takes the shared chart props, plus: Prop Name | Type | Default | Description `maxValue` | `number` | data maximum | Pins the outer ring to a fixed value. `startAngle` | `number` | `0` | Degrees to rotate the first category away from 12 o’clock. `interactive={true}` resolves to `'overlay'` here, and hover events fire for the nearest vertex. See Types for the shared data and event types. #### Behaviour notes - **Fewer than three categories renders nothing** and warns in development. Two axes cannot enclose a shape. - **Negative values are treated as zero.** A radius below the center has no meaning. - **Missing categories count as zero**, so the shape collapses toward the center on that axis. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart-spider/#slots] ## Chart Spider: Slots #### Chart.Spider.Shape Prop Name | Type | Default | Description `class` | `string` | `""` | CSS classes applied to every shape. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to every shape. `fillOpacity` | `number` | `0.25` | Fill opacity. Keep it low when shapes overlap. `strokeWidth` | `ChartLength` | `'0.125rem'` | Outline width. `pointRadius` | `ChartLength` | `'0.1875rem'` | Vertex marker radius. `0` hides the markers. #### Chart.Spider.Web Prop Name | Type | Default | Description `class` | `string` | `""` | CSS classes applied to every ring. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to every ring. `levels` | `number` | `4` | Concentric rings drawn behind the data. `shape` | `'polygon' \| 'circle'` | `'polygon'` | Whether rings follow the axes or are true circles. #### Chart.Spider.Axis Prop Name | Type | Default | Description `class` | `string` | `""` | Applied to both the spokes and the category labels. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to the spokes. `line` | `boolean` | `true` | Draws the spoke from the center to each category. `format` | `(category: string) => string` | `undefined` | Formats the category name. Category labels are HTML placed just outside the outer ring and aligned by quadrant so they extend away from the web instead of over it. #### Chart.Legend, Chart.Tooltip, Chart.Labels Shared with every chart type. See Shared slots for their props. `Chart.Labels` places a value just above each vertex. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart/] ## Chart `Chart` is a family of data-visualisation components. They share one data model, one palette, one animation system, and one set of slots, so the knowledge you build on one chart applies to the rest. Component | Use it for `Chart.Pie` | Parts of a whole with a small number of slices. `Chart.Donut` | Same as pie, with a total or hovered value in the middle. `Chart.Bar` | Comparing values across categories and series. `Chart.Line` | A value traced across ordered categories. `Chart.Area` | Same as line when filled magnitude or summed series matter. `Chart.Spider` | Several measures at once, where the overall shape is the point. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart/#the-data-model] ## Chart: The data model Every chart takes the same `data` array. Each item is a series, and each series holds data points. ```ts interface ChartPoint { type: string; // category key; it is the identity used across data changes value: number; color?: string; // overrides the series colour label?: string; // display text, defaults to `type` meta?: Record; // forwarded to tooltips and callbacks } interface ChartSeries { points: ChartPoint[]; id?: string; // stable identity across data changes; defaults to the index label?: string; color?: string; class?: string; style?: JSX.CSSProperties; } ``` Pie, donut, and spider read one series. Bar, line, and area read as many as you give them. `data` is reactive: feed it from a signal and the chart follows every change. Two rules are worth knowing: - **Categories are the union of every series.** If one series declares a category that another omits, it counts as `0`, so series do not need to match exactly. A line chart can treat this differently with `connectNulls`. - **`type` is identity.** It is how a point is matched to its previous version when the data changes, which is what allows smooth animation instead of snapping. **Caution:** A chart fills its container, so the container must have a size. A chart inside an element with no height renders nothing. Size it through the chart’s own `class` or `style`, or give its parent a height. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart/#colours] ## Chart: Colours Marks take their colour from a built-in eight-slot categorical palette, assigned by index: ```plaintext point.color ?? series.color ?? palette[index % palette.length] ``` The palette is tuned for colourblind separation on both light and dark surfaces. Its order matters: neighbouring colours are the most distinct, because neighbouring marks are the ones people compare. To use your own colours, pass a `palette`: ```tsx ``` Hiding a series from the legend does not change the colours of the others. **Note:** After eight series the palette repeats and stops being a reliable identifier. The chart warns in development. Prefer fewer series, an “other” bucket, or several smaller charts. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart/#animation] ## Chart: Animation Animation is off by default. Pass an `animation` object and the chart tweens between data sets: ```tsx ``` Field | Default | Effect `duration` | `300` | Milliseconds. `0` snaps. `easing` | `'ease-out'` | `'linear'`, `'ease-in'`, `'ease-out'`, `'ease-in-out'`, or a custom `(t) => number`. `delay` | `0` | Milliseconds before the animation starts. `stagger` | `0` | Extra delay for each mark, for a cascading entrance. `onStart` / `onEnd` | — | Lifecycle callbacks. What you get: - **Values interpolate, not pictures.** Geometry is rebuilt every frame, so every intermediate state is real geometry rather than a morph between two shapes. - **Marks enter from nothing.** A new slice grows in place instead of popping in. - **Marks leave gracefully.** A removed slice shrinks away instead of blinking out. - **Interrupting is safe.** Changing the data mid-animation continues from the current state without a snap-back. - **Lines reveal themselves.** A line or area given an animation on mount reveals from one end. With no `animation` prop, a mounted chart does zero per-frame work. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart/#interactivity] ## Chart: Interactivity Interactivity is also off by default. A chart with no `interactive` prop attaches no listeners and sets `pointer-events: none`, so input passes straight through to the game underneath. ```tsx inspect(e.point.type)}>
{e.series.label}: {e.point.value}
} />
``` Value | Behaviour omitted / `false` | No listeners. `true` | Uses the correct hit model for the chart type. `"svg"` | Native SVG pointer events, one listener per mark. `"overlay"` | A single transparent overlay resolves the hovered mark mathematically. `true` resolves to native SVG events for pie, donut, and bar, and to overlay mode for line, area, and spider: - A 2px line stroke is effectively impossible to target, so those charts resolve the nearest vertex and snap the tooltip to it, which makes the crosshair readable. - A spider series is a single closed path spanning every category, so native hit-testing can only answer “which series” and not “which point”. **Caution:** Native SVG hit-testing requires Gameface 3.1.1 or newer. On older versions, use `interactive="overlay"`, which works everywhere. It is also the better choice for large data sets: native mode attaches listeners per mark, while the overlay attaches one listener total. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart/#lengths] ## Chart: Lengths Props that set a size — such as a corner radius, a stroke width, or the donut hole — accept either a number or a CSS length string: Value | Meaning `4` or `'4px'` | Pixels. Fixed at every resolution. `'0.25rem'` | Relative to the root font size, so it scales with the rest of the UI. `'1vh'`, `'1vw'`, `'1vmin'`, `'1vmax'` | Relative to the viewport. `'60%'` | A share of something the chart measures. This is only valid where the prop says it is. Most defaults are in `rem`, so unchanged charts scale with your UI. Prefer `rem` for your own values too, unless you want a fixed size at every resolution. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart/#shared-props] ## Chart: Shared props Every chart type takes these, alongside its own props. Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to the chart root. `class` | `string` | `""` | Additional CSS classes applied to the chart. `data` | `ChartSeries[]` | `[]` | The series to plot. Reactive. `palette` | `string[]` | built-in | Overrides the default categorical palette. `animation` | `ChartAnimation` | `undefined` | Enables tweening between data sets. Omit for no animation. `interactive` | `boolean \| 'svg' \| 'overlay'` | `false` | Enables hover, tooltip, and click behavior. See Interactivity. `onPointHover` | `(event: ChartPointEvent \| null) => void` | `undefined` | Fires when the hovered point changes; `null` on leave. `onPointClick` | `(event: ChartPointEvent) => void` | `undefined` | Fires when a point is clicked. `onSeriesToggle` | `(seriesIndex: number, visible: boolean) => void` | `undefined` | Fires when an entry is toggled from the legend. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart/#shared-slots] ## Chart: Shared slots (1/3) Charts are configured by their children rather than by a long prop list. Slot | Available on | Purpose `Chart.Legend` | all | Series or slices. Clicking an entry toggles it. `Chart.Tooltip` | all | Follows the hovered point. Requires `interactive`. `Chart.Labels` | all | Direct value labels on the marks. `Chart.XAxis` / `Chart.YAxis` | bar, line, area | Tick labels, formatting, and baseline. `Chart.Grid` | bar, line, area | Gridlines. `Chart..*` | per chart | The marks themselves. See each chart’s page. Everything is opt-in. No `Chart.Grid`, no gridlines; no `Chart.Legend`, no legend. #### Legend Prop Name | Type | Default | Description `class` | `string` | `""` | CSS classes applied to the legend container. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to the legend container. `position` | `'top' \| 'bottom' \| 'left' \| 'right'` | `'bottom'` | Which edge the legend sits on. `interactive` | `boolean` | `true` | Whether clicking an entry toggles it. `content` | `(entry: LegendEntry) => JSX.Element` | `undefined` | Replaces the markup of a single entry. Pie and donut legends list slices; every other chart lists series. Hiding an entry does not change the colours of the others. ```tsx } /> ``` #### Tooltip Only rendered while a point is hovered, so it requires `interactive`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart/#shared-slots] ## Chart: Shared slots (2/3) Prop Name | Type | Default | Description `class` | `string` | `""` | CSS classes applied to the tooltip. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to the tooltip. `position` | `'top' \| 'bottom' \| 'left' \| 'right' \| 'auto'` | `'auto'` | Which side of the pointer the tooltip sits on. `auto` flips away from the viewport edge. `offset` | `ChartLength` | `'0.75rem'` | Distance between the pointer and the tooltip. `content` | `(event: ChartPointEvent) => JSX.Element` | `undefined` | Replaces the tooltip markup. #### Labels Direct labels drawn as HTML over the chart. Prop Name | Type | Default | Description `class` | `string` | `""` | CSS classes applied to every label. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to every label. `show` | `'always' \| 'hover' \| 'never'` | `'always'` | When labels are visible. `format` | `(point: ChartPoint, series: ChartSeries) => string` | `undefined` | Builds the label text. Defaults to the point’s `label` (then `type`) on a pie or donut slice and to its value elsewhere. `placement` | `'inside' \| 'outside' \| 'hole'` | `'inside'` | Pie and donut only. `'hole'` is donut only. `leaderLines` | `boolean` | `false` | Pie and donut only. Connects each slice to its outside label. The label position depends on the chart: inside or outside each slice on a pie, centered in each bar, and just above each vertex on line, area, and spider charts. #### XAxis and YAxis --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart/#shared-slots] ## Chart: Shared slots (3/3) Which one is the value axis depends on the chart orientation: `YAxis` on a vertical chart and `XAxis` on a horizontal bar chart. Omit a slot to hide that axis entirely. Prop Name | Type | Default | Description `class` | `string` | `""` | CSS classes applied to every tick label on this axis. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to every tick label. `ticks` | `number` | `5` | A hint for how many ticks to aim for. Values are still chosen to be round. `format` | `(value: number \| string) => string` | `undefined` | Formats the tick label. `line` | `boolean` | `true` | Draws the zero baseline. `hide` | `boolean` | `false` | Hides the axis while keeping its space reserved. #### Grid Prop Name | Type | Default | Description `class` | `string` | `""` | CSS classes applied to every gridline. `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to every gridline. `horizontal` | `boolean` | `true` | Lines across the value axis. `vertical` | `boolean` | `false` | Lines along the category axis. `ticks` | `number` | `5` | How many gridlines to aim for. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart/#types] ## Chart: Types `ChartPoint` and `ChartSeries` are described under the data model. ```ts type ChartLength = number | string; // see "Lengths" above interface ChartAnimation { duration?: number; // ms; default 300, 0 snaps easing?: 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | ((t: number) => number); delay?: number; stagger?: number; // extra delay per mark onStart?: () => void; onEnd?: () => void; } interface ChartPointEvent { point: ChartPoint; series: ChartSeries; seriesIndex: number; pointIndex: number; position: { x: number; y: number }; // within the chart, in pixels } interface LegendEntry { label: string; color: string; seriesIndex: number; pointIndex?: number; // set when the entry is a single slice visible: boolean; } ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart/#performance] ## Chart: Performance These charts are built to sit in a HUD that shares a frame with the game. Concern | Guidance Mark count | One SVG path per mark. Comfortable to roughly 200; the chart warns past 500. Animation | One signal write per frame regardless of mark count. Above roughly 200 animated marks, prefer no animation. Hit-testing | `"svg"` attaches three listeners per mark; `"overlay"` attaches one total. Above roughly 100 marks, prefer the overlay. Labels | One element per visible label. Above roughly 20 points, prefer ``. Idle | With neither animation nor interactivity, a chart costs nothing per frame. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/chart/#accessibility] ## Chart: Accessibility - Show a legend whenever there are two or more series. Identity should never rely on colour alone. - With a handful of marks, direct labels (`Chart.Labels`) beat a legend because they place the name next to the thing. - Text uses text colours, never the series colour. A coloured mark next to a label carries the identity. - Avoid a second value axis. Two measures of different scales belong in two charts or should be indexed to a common base. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/] ## Modal The `Modal` component is a flexible and customizable dialog used to display content over the main UI of your application. To provide greater control, `Modal` supports multiple slots, allowing you to override the default overlay and modal window structure with your own content and styles. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/#installation] ## Modal: Installation Every component ships with the boilerplate. If you are working in your own project, add `Modal` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Modal ``` The CLI pulls in whatever `Modal` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/#usage] ## Modal: Usage (1/2) Using the `Modal` component is simple. You can import it and incorporate it into your app as shown below: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/#usage] ## Modal: Usage (2/2) ```tsx import Modal from '@components/Feedback/Modal/Modal'; import ModalCloseIcon from '@components/Feedback/Modal/ModalCloseIcon.svg?component-solid'; import Block from '@components/Layout/Block/Block'; import Flex from '@components/Layout/Flex/Flex'; import Top from '@components/Layout/Top/Top'; import Content from '@components/Layout/Content/Content'; import Bottom from '@components/Layout/Bottom/Bottom'; import Button from '@components/Basic/Button/Button'; const App = () => { return ( Modal title Content ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/#api] ## Modal: API #### Props Prop | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to the modal’s root element. `class` | `string` | `""` | Additional CSS classes to customize the modal’s appearance. `ref` | `ModalRef \| undefined` | `undefined` | Reference to the modal instance. You can use it to call methods like `open()` or `close()` programmatically. `open` | `boolean` | `false` | Determines whether the modal is initially visible. `onOpen` | `() => void` | `undefined` | Callback invoked when the modal is opened. `onClose` | `() => void` | `undefined` | Callback invoked when the modal is closed. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/#ref-api] ## Modal: Ref API To interact with the `Modal` programmatically, you can use the `ModalRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the modal’s root HTML element, useful for DOM access or styling. #### Methods Method | Parameters | Returns | Description `open()` | \- | `void` | Opens the modal programmatically. `close()` | \- | `void` | Closes the modal programmatically. `isOpen()` | \- | `boolean` | Returns `true` if the modal is currently open; otherwise, returns `false`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/#slots] ## Modal: Slots (1/2) #### Modal.Overlay This slot lets you define the modal’s background overlay. Use it to enable or customize the overlay that appears behind the modal window. **Note:** The `Modal` component does not include an overlay by default. To enable it, you must explicitly add the `Modal.Overlay` slot. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied directly to the overlay element. `class` | `string` | `""` | CSS classes for additional overlay styling. ##### Usage ```tsx import Modal from '@components/Feedback/Modal/Modal'; const App = () => { return ( ); }; export default App; ``` #### Modal.Window Use this slot to define and customize the modal window itself. This is where you place your dialog content. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles for the modal window. `class` | `string` | `""` | Additional CSS classes for custom styling. `children` | `JSX.Element` | `""` | Content to be displayed inside the window. ##### Usage ```tsx import Modal from '@components/Feedback/Modal/Modal'; const App = () => { return ( Content and structure of the modal dialog goes here. ); }; export default App; ``` #### Modal.Close --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/#slots] ## Modal: Slots (2/2) The `Modal.Close` slot is used to wrap any element that should trigger the closing of the modal when clicked. This is typically a button or an icon, but it can be any clickable element. The slot can be placed anywhere inside the modal window and used multiple times if needed. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles for the close button. `class` | `string` | `""` | Additional CSS classes for styling the close button. `children` | `JSX.Element` | `""` | Content rendered inside the button (e.g., text, icon, or custom component). ##### Usage ```tsx import Modal from '@components/Feedback/Modal/Modal'; import Button from '@components/Basic/Button/Button'; const App = () => { return ( ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/#guide] ## Modal: Guide (1/6) #### Customizing the Modal Window By default, the `Modal.Window` slot provides a basic layout - a white background with no predefined content. This minimalist setup allows you to fully customize the modal window according to your needs. You can insert any content within `Modal.Window`, including text, buttons, or other components. To help structure the modal’s layout, you can use the `Top`, `Content`, and `Bottom` components. These subcomponents make it easier to build consistent and flexible modal designs by organizing the content into clear sections. Refer to the first example on this page for a demonstration of how to use these components. #### Creating a Modal with a Background Behind the Content To add a background specifically behind the content of a modal, you can again use the `Top`, `Content`, and `Bottom` components for structure. Use `Top` for titles or headers and `Content` for the main area of the modal. To customize the content background, apply a background image or color to the `Content` component. Then, remove the `Modal.Window` background by setting its style to none. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/#guide] ## Modal: Guide (2/6) ```tsx import Button from '@components/Basic/Button/Button'; import Modal from '@components/Feedback/Modal/Modal'; import ModalCloseIcon from '@components/Feedback/Modal/ModalCloseIcon.svg?component-solid'; import Block from '@components/Layout/Block/Block'; import Flex from '@components/Layout/Flex/Flex'; import Top from '@components/Layout/Top/Top'; import Content from '@components/Layout/Content/Content'; import Bottom from '@components/Layout/Bottom/Bottom'; import Button from '@components/Basic/Button/Button'; const App = () => { return ( Modal title Content ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/#guide] ## Modal: Guide (3/6) In this example, the background of the Content section is set to an image: `./content-bg.svg`: The result will appear as follows: #### Adding Controls Inside the Modal Content You can enhance the previous example by adding close buttons directly within the modal’s content. Since the `Modal.Close` slot can be used multiple times, it’s perfectly fine to place close buttons inside the `Content` area. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/#guide] ## Modal: Guide (4/6) ```tsx import Modal from '@components/Feedback/Modal/Modal'; import Button from '@components/Basic/Button/Button'; import ModalCloseIcon from '@components/Feedback/Modal/ModalCloseIcon.svg?component-solid'; import Block from '@components/Layout/Block/Block'; import Flex from '@components/Layout/Flex/Flex'; import Top from '@components/Layout/Top/Top'; import Content from '@components/Layout/Content/Content'; import Bottom from '@components/Layout/Bottom/Bottom'; import Button from '@components/Basic/Button/Button'; const App = () => { return ( Modal title Content Content ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/#guide] ## Modal: Guide (5/6) You can also attach click handlers to the `Accept` and `Reject` buttons to trigger specific actions when modal closes: ```tsx ``` The end result will look like this: #### Opening and Closing the Modal Programmatically The `Modal` component also allows you to control its state through code. ##### Steps 1. Create a ref of type `ModalRef` and bind it to the `Modal` component. 2. Use `ref.open()` and `ref.close()` methods to toggle the modal programmatically (e.g., via keyboard or external UI control). --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/modal/#guide] ## Modal: Guide (6/6) ```tsx import Modal, { ModalRef } from '@components/Feedback/Modal/Modal'; import ModalCloseIcon from '@components/Feedback/Modal/ModalCloseIcon.svg?component-solid'; import Block from '@components/Layout/Block/Block'; import Flex from '@components/Layout/Flex/Flex'; import Top from '@components/Layout/Top/Top'; import Content from '@components/Layout/Content/Content'; import Bottom from '@components/Layout/Bottom/Bottom'; import Button from '@components/Basic/Button/Button'; import { onMount } from 'solid-js'; const App = () => { let ref!: ModalRef; const handleKeyDown = (e: KeyboardEvent) => { if (e.keyCode === 13 && ref.isOpen()) { ref.close(); } }; onMount(() => { window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }); return ( <> Modal title Content ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/progress-bar/] ## Progress Bar The `Progress.Bar` component is used to visually indicate the progress of a task or operation. It provides a horizontal bar that fills up as a task or operation progresses, giving users feedback on the completion status. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/progress-bar/#installation] ## Progress Bar: Installation Every component ships with the boilerplate. If you are working in your own project, add `Progress` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Progress ``` The CLI pulls in whatever `Progress` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/progress-bar/#usage] ## Progress Bar: Usage To use the `Progress.Bar` component, import it from the library and include it in your JSX code. To make it functional you need to provide a value to the `progress` prop. The value should be a number between `0` and `100`, representing the percentage of completion. The `Progress.Bar` will react to changes in the `progress` prop and update its visual representation accordingly. In the following example, we simulate a task that progresses from `0` to `100` over time using a signal and an interval. **index.tsx:** ```tsx import Progress from '@components/Feedback/Progress/Progress'; import { createSignal, onMount } from 'solid-js'; const App = () => { const [progress, setProgress] = createSignal(0); const simulateProgress = (to: number) => { let interval = setInterval(() => setProgress(prev => { if (prev >= to) { clearInterval(interval); return prev; } return prev + 1; }), 100); }; onMount(() => { simulateProgress(100); }); return ( ); }; ``` **Caution:** The `Progress.Bar` component is a controlled component, meaning that it relies on the `progress` prop to determine its state. It does not manage its own state internally. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/progress-bar/#api] ## Progress Bar: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the `Progress.Bar`’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the `Progress.Bar`. `ref` | `HTMLDivElement \| undefined` | `undefined` | Reference to the `Progress.Bar` instance, providing access to the underlying HTML element. `progress` | `number` | `undefined` | The current progress value, represented as a number between `0` and `100`. If the provided value exceeds this range it will be clamped to either `0` or `100`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/progress-bar/#slots] ## Progress Bar: Slots #### Progress.Bar.Fill The `Progress.Bar.Fill` slot is used to customize the fill element of the progress bar. It represents the filled portion of the bar. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the `Progress.Bar.Fill`’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the `Progress.Bar.Fill`’s root element. ##### Usage ```tsx import Progress from '@components/Feedback/Progress/Progress'; const App = () => { const [progress, setProgress] = createSignal(50); return ( ); }; export default App; ``` #### Guide #### Adding a progress bar to a toast You can check how to easily add a progress bar to a toast in the examples of the Toast component documentation --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/progress-circle/] ## Progress Circle The `Progress.Circle` component is used to visually indicate the progress of a task or operation. It provides a circular indicator that fills up, giving users feedback on the completion status. **Caution:** If you are using a version of Gameface before `1.67.0`, the `Progress.Circle` component may not display correctly. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/progress-circle/#installation] ## Progress Circle: Installation Every component ships with the boilerplate. If you are working in your own project, add `Progress` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Progress ``` The CLI pulls in whatever `Progress` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/progress-circle/#usage] ## Progress Circle: Usage To use the `Progress.Circle` component, import it from the library and include it in your JSX code. To make it functional you need to provide a value to the `progress` prop. The value should be a number between `0` and `100`, representing the percentage of completion. The `Progress.Circle` will react to changes in the `progress` prop and update its visual representation accordingly. In the following example, we simulate a task that progresses from `0` to `100` over time using a signal and an interval. **index.tsx:** ```tsx import Progress from '@components/Feedback/Progress/Progress'; import { createSignal, onMount } from 'solid-js'; const App = () => { const [progress, setProgress] = createSignal(0); const simulateProgress = (to: number) => { let interval = setInterval(() => setProgress(prev => { if (prev >= to) { clearInterval(interval); return prev; } return prev + 1; }), 100); }; onMount(() => { simulateProgress(100); }); return ( {`${progress()}%`} ); }; ``` **Caution:** The `Progress.Circle` component is a controlled component, meaning that it relies on the `progress` prop to determine its state. It does not manage its own state internally. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/progress-circle/#api] ## Progress Circle: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the `Progress.Circle`’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the `Progress.Circle`. `ref` | `HTMLDivElement \| undefined` | `undefined` | Reference to the `Progress.Circle` instance, providing access to the underlying HTML element. `progress` | `number` | `undefined` | The current progress value, represented as a number between `0` and `100`. If the provided value exceeds this range it will be clamped to either `0` or `100`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/progress-circle/#slots] ## Progress Circle: Slots (1/2) #### Progress.Circle.Fill The `Progress.Circle.Fill` slot is used to customize the fill element of the progress circle. It represents the filled portion of the progress circle. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the `Progress.Circle.Fill`’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the `Progress.Circle.Fill`. `shape` | `square` \| `round` | `square` | The shape of the filled portion of the circle. ##### Usage ```tsx import Progress from '@components/Feedback/Progress/Progress'; const App = () => { const [progress, setProgress] = createSignal(50); return ( ); }; export default App; ``` **Tip:** To customize the color of the `Progress.Circle.Fill`, you can use the `stroke` CSS property. #### Progress.Circle.Outline The `Progress.Circle.Outline` slot is used to customize the outline element of the progress circle. It represents the unfilled portion of the progress circle. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the `Progress.Circle.Outline`’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the `Progress.Circle.Outline`. ##### Usage --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/progress-circle/#slots] ## Progress Circle: Slots (2/2) ```tsx import Progress from '@components/Feedback/Progress/Progress'; const App = () => { const [progress, setProgress] = createSignal(50); return ( ); }; export default App; ``` **Tip:** To customize the color of the `Progress.Circle.Outline`, you can use the `stroke` CSS property. #### Progress.Circle.Text The `Progress.Circle.Text` slot is used to display content inside the progress circle. If no text slot is provided, the progress circle will not display any content by default. You can use it to display the current progress percentage or any other relevant information. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the `Progress.Circle.Text`’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the `Progress.Circle.Text`’s root element. `children` | `JSX.Element` | `""` | Content to be rendered inside the text slot. This can be used to display the current progress ##### Usage ```tsx import Progress from '@components/Feedback/Progress/Progress'; const App = () => { const [progress, setProgress] = createSignal(50); return ( {`${progress()}%`} ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/progress-circle/#guide] ## Progress Circle: Guide #### Visually customizing the Progress Circle component You can visually customize the `Progress.Circle` component by using the provided slots to change the appearance of the fill, outline, and text elements. ##### Removing the circle’s outline To remove the outline simply provide the `Progress.Circle.Outline` slot and set its `stroke-width` to `0` with either a class or an inline style. ```tsx ``` ##### Changing the starting position of the fill By default, the fill starts at the top (12 o’clock position) and progresses clockwise. To change the starting position, you can use CSS transforms on the `Progress.Circle` component. ```tsx ``` Now the progress bar will start at the 3 o’clock position and progress clockwise. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/toast/] ## Toast The `Toast` component is a notification element that displays brief messages to the user. It allows users to receive feedback about an operation or to display important information. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/toast/#installation] ## Toast: Installation Every component ships with the boilerplate. If you are working in your own project, add `Toast` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Toast ``` The CLI pulls in whatever `Toast` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/toast/#usage] ## Toast: Usage To include a toast in your UI, call the `createToast` function with the desired options and include the `Toaster` component in your JSX. **index.tsx:** ```tsx import useToast from '@components/Feedback/Toast/toast'; const App = () => { const [Toaster, createToast] = useToast(); // Example of creating a toast const showToast = () => { createToast({ body: () => <>This is a toast message, position: 'top-right', // Position of the toast on the screen timeout: 3000, // Duration in milliseconds before the toast disappears }); }; return ( <> ); }; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/toast/#api] ## Toast: API #### createToast(options: ToastOptions) Creates a new toast notification with the specified options. ##### Parameters Option Name | Type | Default | Description `body` | `string \| JSX.Element` | `""` | The content of the toast message. Can be a string or JSX element. `position` | `'top-left' \| 'top-center' \| 'top-right' \| 'middle-left' \| 'middle-center' \| 'middle-right' \| 'bottom-left' \| 'bottom-center' \| 'bottom-right'` | `'top-right'` | The position on the screen where the toast will appear. `timeout` | `number` | `0` | Duration in milliseconds before the toast disappears. `0` makes the toast persistent. ##### Body Arguments When defining the body function, you receive the following helpers: Argument | Type | Description `close` | `(children: JSX.Element) => JSX.Element` | A wrapper function that attaches a click-to-close listener to any element. `progress` | `() => number` | A signal returning the current lifetime of the toast (0 to 20). `dismiss` | `() => void` | A function to programmatically remove the toast from the UI. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/toast/#guide] ## Toast: Guide (1/4) #### Adding a close button To allow the user to close the toast manually you can include the `Close` button inside the `body`: ```tsx import useToast from '@components/Feedback/Toast/toast'; const App = () => { const [Toaster, createToast] = useToast(); // Example of creating a toast const showToast = () => { createToast({ body: (close) => ( <> This is a toast message {close()} ), position: 'top-right', // Position of the toast on the screen timeout: 3000, // Duration in milliseconds before the toast disappears }); }; return ( <> ); }; export default App; ``` #### Adding a progress bar You can display a progress bar inside your toast by using the `progress` signal within the `body` function, together with the `Progress.Bar` component: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/toast/#guide] ## Toast: Guide (2/4) ```tsx import useToast from '@components/Feedback/Toast/toast'; import Progress from '@components/Feedback/Progress/Progress'; const App = () => { const [Toaster, createToast] = useToast(); // Example of creating a toast const showToast = () => { createToast({ body: (close, progress) => ( <> This is a toast message
{close()} ), position: 'top-right', // Position of the toast on the screen timeout: 3000, // Duration in milliseconds before the toast disappears }); }; return ( <> ); }; export default App; ``` **Caution:** If you try to use the `progress` signal outside the return of the `body` function, it will rerender the entire toast every time the progress updates, which can lead to performance issues. **Note:** The `progress` signal returns a value between `0` and `20` to allow for smoother progress bar and to not harm performance. If you want to get a value between `0` and `100`, you can multiply the value by `5`. #### Adding entrance animations You can add entrance animations to the toast by adding CSS classes to the `body` element: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/toast/#guide] ## Toast: Guide (3/4) ```tsx import useToast from '@components/Feedback/Toast/toast'; const App = () => { const [Toaster, createToast] = useToast(); // Example of creating a toast const showToast = () => { createToast({ body: (close) => (
This is a toast message {close()}
), position: 'top-right', // Position of the toast on the screen timeout: 3000, // Duration in milliseconds before the toast disappears }); }; return ( <> ); }; export default App; ``` ```css @keyframes fade-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } } .animate-fade-in { animation: fade-in 0.5s ease-out; } ``` #### Programmatic Closing While the `close` wrapper is convenient for standard buttons, you may need to close a `toast` programmatically after an logic-heavy action (like starting a tutorial or responding to a gamepad event). The `dismiss` function allows you to trigger the removal logic directly without relying on DOM click events. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/toast/#guide] ## Toast: Guide (4/4) ```tsx import useToast from '@components/Feedback/Toast/toast'; const App = () => { const [Toaster, createToast] = useToast(); const showToast = () => { createToast({ body: (close, progress, dismiss) => (
Proceed with Action? {/* Fallback for simple UI closing */} {close()}
), position: 'top-center', timeout: 0, // Persistent until dismissed }); }; return ( <> ); }; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/] ## Tooltip The `Tooltip` component is a flexible and customizable way to display contextual information when users hover, focus, or click on an element. It improves usability by providing additional context without overcrowding the interface. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#installation] ## Tooltip: Installation Every component ships with the boilerplate. If you are working in your own project, add `Tooltip` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Tooltip ``` The CLI pulls in whatever `Tooltip` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#usage] ## Tooltip: Usage (1/2) The `Tooltip` works by wrapping a target element inside a relatively positioned container and displaying a tooltip message absolutely positioned relative to that target. This ensures the tooltip stays aligned with the element it describes. The tooltip’s style and behavior can be customized to fit your UI. The component uses event listeners to detect user interaction with the target element and shows or hides the tooltip accordingly. It also supports multiple placement options (`top`, `bottom`, `left`, `right`, or `auto`) to ensure the tooltip is displayed in the most visible position based on available space. Using the `Tooltip` component is simple. Import the `createTooltip` factory function, configure it if necessary, and wrap any element with the `Tooltip` wrapper: **index.tsx:** --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#usage] ## Tooltip: Usage (2/2) ```tsx import createTooltip from '@components/Feedback/Tooltip/tooltip'; import { ParentComponent } from 'solid-js'; const CustomTooltip: ParentComponent<{ title: string, message: string }> = (props) => { return

{props.title}

{props.message}
} const App = () => { const Tooltip = createTooltip({ content: CustomTooltip, action: "hover", position: "bottom" }); return (
Hover for more info
); }; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#api] ## Tooltip: API #### createTooltip(options: TooltipOptions) Creates a new tooltip component with customizable options. ##### Parameters Option Name | Type | Default | Description `content` | `JSX.Element` | `(props: { message: string }) => JSX.Element` | The content of the tooltip message. Can be a JSX element. If not specified, the `message` prop will be used to display a simple text message. `position` | `'top' \| 'bottom' \| 'left' \| 'right' \| 'auto'` | `bottom` | Defines the position of the tooltip relative to the target element. If set to `auto`, the tooltip will automatically choose the best placement based on available space. `action` | `'hover' \| 'click' \| 'focus'` | `hover` | Determines the user interaction that triggers the tooltip.\ `hover`: shows on mouse hover and hides on mouse leave.\ `click`: toggles visibility when the target is clicked.\ `focus`: shows when the target gains focus (e.g., via keyboard) and hides when it loses focus. `onAction` | `Record void>` | `undefined` | Extends or overrides the component’s default navigation action handlers. See Implemented Navigation Actions for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, the tooltip’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#ref-api] ## Tooltip: Ref API To interact with the `Tooltip` programmatically, you can use the `TooltipRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the Tooltip’s wrapper root HTML element, useful for DOM access or styling. #### Methods Method | Parameters | Return Value | Description `show` | none | `void` | Shows the tooltip if it’s hidden. `hide` | none | `void` | Hides the tooltip if it’s visible. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#implemented-navigation-actions] ## Tooltip: Implemented Navigation Actions The `Tooltip` component implements the following navigation action by default: Action Name | Behavior `back` | Dismisses the visible tooltip This allows users to dismiss tooltips using keyboard or gamepad navigation when the tooltip’s target element is focused. ```tsx import createTooltip from '@components/Feedback/Tooltip/tooltip'; const App = () => { // Tooltip with default back action - dismisses on back button press const Tooltip = createTooltip({ action: 'focus' }); return (
Focus me and press ESC
); }; ``` **Navigation Actions Requirements:** For navigation actions to work, the tooltip must use `action: 'focus'` and the wrapped element must be focusable (set `tabindex={0}` or higher on the wrapped element). For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#guide] ## Tooltip: Guide (1/8) #### Customizing tooltip content and appearance By default, if the `content` option is not provided, the `createTooltip` function returns a component that simply displays the text passed via the `message` prop. So for basic usage, you can create a tooltip like this: ```tsx import createTooltip from '@components/Feedback/Tooltip/tooltip'; const App = () => { const Tooltip = createTooltip({ action: "hover", position: "bottom" }); return (
Hover for more info
); }; ``` If you want more flexibility, you can pass a custom JSX element to the `content` option. The `content` option accepts a function that returns JSX and can also be configured to receive additional props. These props can then be passed directly to the tooltip when you use it - for example: ``. In addition, you can style the tooltip wrapper itself using the `style` or `class` props that are exposed on the `Tooltip` component. Here’s an example showing how to create a custom tooltip with both custom styling and custom content: ```scss .tip { color: white; width: 10vmax; &-message { background-color: rgb(0, 132, 255); } } .wrapper { display: flex; justify-content: center; color: white; width: 10vmax; } ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#guide] ## Tooltip: Guide (2/8) ```tsx import createTooltip from '@components/Feedback/Tooltip/tooltip'; import { ParentComponent } from 'solid-js'; import styles from './styles.module.scss'; const CustomTooltip: ParentComponent<{ message: string }> = (props) => { return
{props.message}
} const App = () => { const Tooltip = createTooltip({ content: CustomTooltip }); return (
Hover for more info
); }; export default App; ``` #### Positioning the tooltip The `Tooltip` component supports flexible positioning near the target element. You can configure the position using the position option when creating the tooltip. Available values are: - `top` - `bottom` - `left` - `right` - `auto` (automatically adjusts based on available space to ensure visibility) If the `position` option is not specified, the default is `bottom`. Here’s an example demonstrating different tooltip positions: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#guide] ## Tooltip: Guide (3/8) ```tsx import createTooltip from '@components/Feedback/Tooltip/tooltip'; const App = () => { const TooltipTop = createTooltip({ position: 'top' }); const TooltipBottom = createTooltip({ position: 'bottom' }); const TooltipLeft = createTooltip({ position: 'left' }); const TooltipRight = createTooltip({ position: 'right' }); const TooltipAuto = createTooltip({ position: 'auto' }); return (
Bottom
Left Right
Top
Auto
); }; export default App; ``` Running this example, notice how the `auto` position adapts when the target element is near the bottom of the viewport. Instead of rendering off-screen, the tooltip automatically flips above the target element to remain visible. #### Configuring tooltip trigger actions --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#guide] ## Tooltip: Guide (4/8) The `Tooltip` component can be configured to respond to different types of user interactions on the target element by setting the `action` option when creating the tooltip. The supported actions are: - **`hover`** (default) - The tooltip appears when the user hovers over the target element and disappears when the mouse leaves. - **`click`** - The tooltip toggles visibility when the target element is clicked. Clicking again on the target hides it. This mode is useful when you want to let users access information on demand without requiring hover. - **`focus`** - The tooltip appears when the target element gains focus (e.g., through keyboard navigation or tabbing) and disappears when it loses focus. This option is particularly helpful for improving accessibility, ensuring that keyboard users have access to the same contextual information. Here’s an example showing how to create tooltips with different trigger actions: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#guide] ## Tooltip: Guide (5/8) ```tsx import createTooltip from '@components/Feedback/Tooltip/tooltip'; const App = () => { const TooltipHover = createTooltip({ action: 'hover' }); const TooltipClick = createTooltip({ action: 'click' }); const TooltipFocus = createTooltip({ action: 'focus' }); return (
Hover Click
); }; export default App; ``` #### Adding an arrow to the tooltip To improve clarity and make it visually obvious that a tooltip is associated with its target element, you can add an arrow (pointer) to the tooltip. This arrow can be implemented using CSS pseudo-elements (`::after`) and positioned absolute to the tooltip based on its alignment (`top`, `bottom`, `left`, or `right`). Here’s an example of how to implement arrows for each position using SCSS: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#guide] ## Tooltip: Guide (6/8) ```scss .tip { color: white; position: relative; $arrow-size: 0.5vmax; &-message { background-color: rgb(0, 132, 255); padding: 0.5vmax 1vmax; justify-content: center; border-radius: 0.5vmax; position: relative; } &::after { content: ''; position: absolute; width: 0; height: 0; border-style: solid; } &.top { margin-bottom: $arrow-size; } &.bottom { margin-top: $arrow-size; } &.left { margin-right: $arrow-size; } &.right { margin-left: $arrow-size; } &.top::after { bottom: -$arrow-size; left: 50%; transform: translateX(-50%); border-width: $arrow-size $arrow-size 0 $arrow-size; border-color: rgb(0, 132, 255) transparent transparent transparent; } &.bottom::after { top: -$arrow-size; left: 50%; transform: translateX(-50%); border-width: 0 $arrow-size $arrow-size $arrow-size; border-color: transparent transparent rgb(0, 132, 255) transparent; } &.left::after { top: 50%; right: -$arrow-size; transform: translateY(-50%); border-width: $arrow-size 0 $arrow-size $arrow-size; border-color: transparent transparent transparent rgb(0, 132, 255); } &.right::after { top: 50%; left: -$arrow-size; transform: translateY(-50%); border-width: $arrow-size $arrow-size $arrow-size 0; border-color: transparent rgb(0, 132, 255) transparent transparent; } } .wrapper { color: white; } ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#guide] ## Tooltip: Guide (7/8) ```tsx import createTooltip from '@components/Feedback/Tooltip/tooltip'; import { ParentComponent } from 'solid-js'; import styles from './styles.module.scss'; const CustomTooltip: ParentComponent<{ message: string, arrowPosition: 'top' | 'bottom' | 'left' | 'right' }> = (props) => { return
{props.message}
} const App = () => { const TooltipTop = createTooltip({ content: CustomTooltip, position: 'top' }); const TooltipBottom = createTooltip({ content: CustomTooltip, position: 'bottom' }); const TooltipLeft = createTooltip({ content: CustomTooltip, position: 'left' }); const TooltipRight = createTooltip({ content: CustomTooltip, position: 'right' }); return (
Bottom
Left Right
Top
); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/feedback/tooltip/#guide] ## Tooltip: Guide (8/8) **Caution:** When using the `auto` position, adding an arrow is not currently supported because the tooltip’s position is determined dynamically at runtime based on available space in the viewport. #### Using the tooltip with an absolutely positioned element --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/absolute/] ## Absolute The `Absolute` component is a structural element designed to wrap content and position it precisely, independent of the normal document structure. It is ideal for creating dynamic notifications, pop-ups, overlays, moving nameplates, and other UI elements that require precise placement. By default, the `Absolute` component positions its content relative to the closest `Relative` component parent. If no `Relative` component is present, it positions relative to the body. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/absolute/#installation] ## Absolute: Installation Every component ships with the boilerplate. If you are working in your own project, add `Absolute` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Absolute ``` The CLI pulls in whatever `Absolute` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/absolute/#usage] ## Absolute: Usage The primary use case for the `Absolute` component is to position nested content precisely within a document. The component lets you define offsets using the `top`, `left`, `right`, and `bottom` properties. **index.tsx:** ```tsx import Relative from '@components/Layout/Relative/Relative'; import Absolute from '@components/Layout/Absolute/Absolute'; import Block from '@components/Layout/Block/Block'; Content with top and right offset by 50px ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/absolute/#api] ## Absolute: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `top`, `left`, `right`, `bottom` | `string` | `""` | Specify the position offset of the `Absolute` component. It accepts any valid css unit value `center` | `boolean \| 'x' \| 'y'` | `undefined` | Specifies whether to center the component within its closest relatively positioned ancestor (usually a `Relative` component). Use a boolean to center on both axes, or specify `'x'` or `'y'` for a single axis. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/absolute/#guide] ## Absolute: Guide (1/2) #### Positioning the component The primary purpose of the `Absolute` component is to position content precisely. To achieve optimal control, it is recommended to nest the `Absolute` component within a `Relative` component. This allows the `Relative` component to act as a bounding box, ensuring the `Absolute` component is positioned relative to it rather than the document or screen. ##### Example ```tsx import Relative from '@components/Layout/Relative/Relative'; import Absolute from '@components/Layout/Absolute/Absolute'; import Block from '@components/Layout/Block/Block'; const App = () => { return ( Normally positioned content This content is positioned 20px from the top and 40px from the left of the Relative container. Positioned at the bottom right corner of the Relative container. ); }; export default App; ``` #### Accessing the HTML element To access the HTML DOM element of the `Absolute` component. 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `Absolute` component ##### Example --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/absolute/#guide] ## Absolute: Guide (2/2) ```tsx import Relative from '@components/Layout/Relative/Relative'; import Absolute from '@components/Layout/Absolute/Absolute'; import Block from '@components/Layout/Block/Block'; const App = () => { let absoluteRef!: HTMLDivElement; return ( Content with top and right offset by 50px ); }; export default App; ``` Now you can access the HTML element of the component with `absoluteRef` and make modifications to it if needed. #### Quickly centering an element within a container 3.0.0 The `center` prop easily centers an `Absolute` component within its closest relatively positioned ancestor. You can center it on both axes or restrict it to a single axis. This is particularly useful for quickly centering elements (like text) inside a container without manually calculating offsets. For example, to overlay text in the center of a `Progress.Bar`: 1. Wrap the `Progress.Bar` in a `Relative` component to establish a positioning context. 2. Place the `Absolute` component as a sibling to the `Progress.Bar`. 3. Set the `center` prop on the `Absolute` component to `true` (both axes), or specify `'x'` or `'y'` for a single axis. ```tsx 80% ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/block/] ## Block The `Block` component is a structural element designed to act as an element container. The `Block` component is meant to be used as a wrapper of your other components for logical or styling purposes. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/block/#installation] ## Block: Installation Every component ships with the boilerplate. If you are working in your own project, add `Block` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Block ``` The CLI pulls in whatever `Block` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/block/#usage] ## Block: Usage The default use case for the `Block` component is as an element container. **index.tsx:** ```tsx import Block from '@components/Layout/Block/Block'; Block Content ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/block/#api] ## Block: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `width`, `height` | `string` | `undefined` | Sets the size of the component. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/block/#guide] ## Block: Guide #### Accessing the HTML element To access the HTML DOM element of the `Block` component. 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `HTMLDivElement` 3. Set the declared variable as the value of the `ref` prop of the `Block` component ##### Example ```tsx import Bottom from '@components/Layout/Bottom/Bottom'; import Block from '@components/Layout/Block/Block'; const App = () => { let blockRef!: HTMLDivElement return ( Bottom Section ); }; ``` Now you can access the HTML element of `Block` with `blockRef` and make modifications to it if needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/bottom/] ## Bottom The `Bottom` component is a structural element designed to act as a wrapper of the bottom section of your page. Typically, the `Bottom` component is used alongside the `Top` and `Content` components to achieve better page structure. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/bottom/#installation] ## Bottom: Installation Every component ships with the boilerplate. If you are working in your own project, add `Bottom` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Bottom ``` The CLI pulls in whatever `Bottom` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/bottom/#usage] ## Bottom: Usage The default use case for the `Bottom` component is as a bottom level section container. **index.tsx:** ```tsx import Layout from '@components/Layout/Layout/Layout'; import Top from '@components/Layout/Top/Top'; import Content from '@components/Layout/Content/Content'; import Bottom from '@components/Layout/Bottom/Bottom'; Top Menu Main Content Bottom Section ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/bottom/#api] ## Bottom: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `basis` | `number` | `15%` | Sets the flex-basis of the component as a percentage. For example, a value of `30` sets the flex-basis to `30%`. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/bottom/#guide] ## Bottom: Guide #### Accessing the HTML element To access the HTML DOM element of the `Bottom` component. 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `Bottom` component ##### Example ```tsx import Layout from '@components/Layout/Layout/Layout'; import Top from '@components/Layout/Top/Top'; import Content from '@components/Layout/Content/Content'; import Bottom from '@components/Layout/Bottom/Bottom'; const App = () => { let bottomRef!: HTMLDivElement return ( Top Section Main Content Bottom Section ); }; ``` Now you can access the HTML element of `Bottom` with `bottomRef` and make modifications to it if needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/column/] ## Column The `Column` components are structural elements designed to create grid layouts when used in conjunction with the Row component. Each `Column` component represents a fraction of the row’s width, ranging from `Column.One` (1/12th of the row’s width) to `Column.Twelve` (the entire row’s width). These components leverage a flexbox-based grid system, making it easy to create responsive layouts. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/column/#installation] ## Column: Installation Every component ships with the boilerplate. If you are working in your own project, add `Column` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Column ``` The CLI pulls in whatever `Column` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/column/#usage] ## Column: Usage The primary use case for the `Column` components is to define the width of content within a `Row` component. If you don’t specify a size, `` equals ``. **index.tsx:** ```tsx import Row from '@components/Layout/Row/Row'; import Column from "@components/Layout/Column/Column"; <> I take 2/12 of the row I take 10/12 of the row (the rest of the row) I take the full row I also take the full row ``` You can also nest rows and columns to create more complex layouts. ```tsx import Row from '@components/Layout/Row/Row'; import Column from "@components/Layout/Column/Column"; const App = () => { return ( Nested column ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/column/#api] ## Column: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/column/#guide] ## Column: Guide (1/2) #### Creating a Grid Layout The `Column` components define the width of their content within a Row. The predefined components (`Column.One` to `Column.Twelve`) correspond to fractions of the row’s total width. For example: - `Column.One`: 1/12th of the row’s width (8.33333%). - `Column.Six`: Half of the row’s width (50%). - `Column.Twelve` or just `Column`: Full row width (100%). ##### Example ```tsx import Row from '@components/Layout/Row/Row'; import Column from "@components/Layout/Column/Column"; const App = () => { return ( I take 8.33333% of the row I take 8.33333% of the row I take 8.33333% of the row I take 8.33333% of the row I take 8.33333% of the row I take 8.33333% of the row I take 50% of the row I take 100% of the row ); }; export default App; ``` #### Accessing the HTML element To access the HTML DOM element of the `Column` component: 1. Declare a variable to hold the ref but don’t initialize it with a value. 2. The declared value should have a type of `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `Column` component. ##### Example --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/column/#guide] ## Column: Guide (2/2) ```tsx import Row from '@components/Layout/Row/Row'; import Column from "@components/Layout/Column/Column"; const App = () => { let columnRef!: HTMLDivElement return ( I take 2/12 of the row ); }; export default App; ``` Now you can access the HTML element of `Column` with `columnRef` and make modifications to it if needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/content/] ## Content The `Content` component is a structural element designed to act as a wrapper of the main section of your page. Typically, the `Content` component is used alongside the `Top` and `Bottom` components to achieve better page structure. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/content/#installation] ## Content: Installation Every component ships with the boilerplate. If you are working in your own project, add `Content` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Content ``` The CLI pulls in whatever `Content` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/content/#usage] ## Content: Usage The primary use case for the `Content` component is as a container for the main content area of the page. **index.tsx:** ```tsx import Layout from '@components/Layout/Layout/Layout'; import Top from '@components/Layout/Top/Top'; import Content from '@components/Layout/Content/Content'; import Bottom from '@components/Layout/Bottom/Bottom'; Top Menu Main Content Bottom Section ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/content/#api] ## Content: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `basis` | `number` | `auto` | Sets the flex-basis of the component as a percentage. For example, a value of `30` sets the flex-basis to `30%`. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/content/#guide] ## Content: Guide #### Accessing the HTML element To access the HTML DOM element of the `Content` component. 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `Content` component ##### Example ```tsx import Layout from '@components/Layout/Layout/Layout'; import Top from '@components/Layout/Top/Top'; import Content from '@components/Layout/Content/Content'; import Bottom from '@components/Layout/Bottom/Bottom'; const App = () => { let contentRef!: HTMLDivElement return ( Top Section Main Content Bottom Section ); }; ``` Now you can access the HTML element of `Content` with `contentRef` and make modifications to it if needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/flex/] ## Flex The `Flex` component is a structural element designed to simplify the creation of flexible and responsive layouts. It is a wrapper that provides easy application for applying CSS flexbox properties. The Flex component supports various configurations for direction, wrapping, alignment, and spacing. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/flex/#installation] ## Flex: Installation Every component ships with the boilerplate. If you are working in your own project, add `Flex` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Flex ``` The CLI pulls in whatever `Flex` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/flex/#usage] ## Flex: Usage The primary use case for the `Flex` component is as a container for flexible and responsive layouts. It abstracts common flexbox properties into easy-to-use props. **index.tsx:** ```tsx import Flex from '@components/Layout/Flex/Flex'; import Block from '@components/Layout/Block/Block'; Item 1 Item 2 Item 3 ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/flex/#api] ## Flex: API (1/2) #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `direction` | `"row"`, `"row-reverse"`, `"column"`, `"column-reverse"` | `"row"` | Specifies the CSS `flex-direction` property, which determines the main axis direction (horizontal or vertical) and the order of items. For example, `"row"` arranges items left-to-right, while `"column-reverse"` arranges them bottom-to-top. `wrap` | `"nowrap"`, `"wrap-reverse"`, `"wrap"` | `"nowrap"` | Specifies the CSS `wrap` property, which controls whether flex items wrap onto multiple lines. For example, `"wrap"` allows items to flow onto new rows or columns, while `"nowrap"` keeps them on a single line. `justify-content` | `"start"`, `"center"`, `"end"`, `"space-between"`, `"space-around"` | `"start"` | Specifies the CSS `justify-content` property, which aligns items along the main axis (horizontal in row and vertical in column). Options like `"space-between"` distribute items with equal gaps, while `"center"` centers them. `align-items` | `"start"`, `"center"`, `"end"`, `"stretch"` | `"stretch"` | Specifies the CSS `align-items` property, which controls the alignment of items along the cross axis (perpendicular to the main axis). For example, `"stretch"` makes all items stretch to fill the container, while `"center"` aligns them in the middle. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/flex/#api] ## Flex: API (2/2) Prop Name | Type | Default | Description `align-content` | `"start"`, `"center"`, `"end"`, `"stretch"` | `"stretch"` | Specifies the CSS `align-content` property, which controls the spacing between rows or columns in a multi-line flex container. For example, `"space-between"` evenly distributes rows, while `"center"` aligns them in the middle of the container. `gap` | `string` | `undefined` | Applies spacing between the elements. It’s a shorthand for both row and column gaps. Requires Gameface 2.2+. `row-gap` | `string` | `undefined` | Vertical spacing between rows of flex items when the container wraps (`flex-wrap: wrap`). Requires Gameface 2.2+. `column-gap` | `string` | `undefined` | Horizontal spacing between columns of flex items in a row (i.e., along the cross axis when `direction="row"`). Requires Gameface 2.2+. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. **Note on Compatibility:** The gap properties require Gameface version 2.2 or higher. If using an older version, these properties will be ignored. Check the console for compatibility warnings. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/flex/#guide] ## Flex: Guide (1/3) #### Creating flexible layouts The `Flex` component provides an intuitive API for creating flexible layouts. ##### Centering content in the middle of the Flex component ```tsx import Flex from '@components/Layout/Flex/Flex'; import Block from '@components/Layout/Block/Block'; const App = () => { return ( Item 1 Item 2 Item 3 ); }; export default App; ``` - `direction="column"` stacks items vertically. - `justify-content="center"` centers items along the main axis. - `align-items="center"` centers items along the secondary axis. ##### Distributing available space between items ```tsx import Flex from '@components/Layout/Flex/Flex'; import Block from '@components/Layout/Block/Block'; const App = () => { return ( Item 1 Item 2 Item 3 Item 4 ); }; export default App; ``` - `justify-content="space-between"` distributes available space equally between the items. - `align-items="center"` centers items along the secondary axis. ##### Nested Flex components --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/flex/#guide] ## Flex: Guide (2/3) To create more complex layout, you can nest as much `Flex` components as you need to achieve your desired layout. ```tsx import Flex from '@components/Layout/Flex/Flex'; import Block from '@components/Layout/Block/Block'; const App = () => { return ( Item 1 Item 2 Item 1 Item 2 ); }; export default App; ``` - `justify-content="space-around"` distributes available space equally around the items. - `align-items="start"` aligns items at the start along the secondary axis. - `direction="column"` stacks items vertically. - `direction="column-reverse"` stacks items vertically in reverse order. #### Accessing the HTML element To access the HTML DOM element of the `Flex` component. 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `Flex` component ##### Example --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/flex/#guide] ## Flex: Guide (3/3) ```tsx import Flex from '@components/Layout/Flex/Flex'; import Block from '@components/Layout/Block/Block'; const App = () => { let flexRef!: HTMLDivElement return ( Item 1 Item 2 Item 3 ); }; ``` Now you can access the HTML element of `Flex` with `flexRef` and make modifications to it if needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid-tile/] ## GridTile The `GridTile` component is content wrapper component made to be used only within the `Grid` component. It is used to specify on which row and column the content inside it should be placed on the `Grid`. **Tile Slot Support:** From Gameface UI version 2.1 onwards, you can access the `GridTile` component as a slot of the `Grid` component, using `Grid.Tile`. The previous method of importing `GridTile` separately is still supported for backward compatibility. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid-tile/#installation] ## GridTile: Installation Every component ships with the boilerplate. If you are working in your own project, add `GridTile` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add GridTile ``` The CLI pulls in whatever `GridTile` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid-tile/#usage] ## GridTile: Usage The `GridTile` component must be provided with the specific row and column through the `rows` and `cols` props. You can dynamically move, remove and replace the tile in specific cells using the provided methods. **index.tsx:** ```tsx import Grid from '@components/Layout/Grid/Grid'; import GridTile from '@components/Layout/GridTile/GridTile'; import Block from '@components/Layout/Block/Block'; Placed in row 2 column 2 Placed in row 3 column 2 Placed in row 3 column 3 ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid-tile/#api] ## GridTile: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `GridTileRef` | `undefined` | Retrieves the `GridTile`’s properties, methods and HTML element and assigns them to a local variable `row` | `number` | `Required` | The row index where the tile will be placed. `col` | `number` | `Required` | The column index where the tile will be placed. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. #### Methods Method | Parameters | Return Value | Description `moveTile` | `newRow`: number, `newCol`: number | `void` | Moves the tile to a different place on the grid. Will throw an error if the row and column don’t exist. `removeItem` | `void` | `void` | Removes the tile from the grid. Will throw an error if the row and column don’t exist. `replaceTile` | `newTile`: JSX.ELement | `void` | Inserts new content on the place of the tile. Will throw an error if the row and column don’t exist. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid-tile/#guide] ## GridTile: Guide (1/3) #### Dynamically Updating the GridTile The `GridTile` component provides methods to dynamically move, remove and replace the component. These methods can be accessed via the `ref` prop. The steps to achieve it are as follows: 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `GridRef`, which you need to import 3. Set the declared variable as the value of the `ref` prop of the `Grid` component 4. Call the methods from the `ref` ##### Example ```tsx import Grid from '@components/Layout/Grid/Grid'; import GridTile { GridTileRef } from '@components/Layout/GridTile/GridTile'; import Block from '@components/Layout/Block/Block'; const App = () => { let gridTileRef!: GridTileRef; const replaceTile = () => { const newBlock = (New) gridTileRef.replaceTile(1, 1, newBlock); } const moveTile = () => { gridRef.moveTile(1, 1); } return ( Placed in row 2 column 2 Replace Tile Move Tile ); }; export default App; ``` #### Making Grid Tiles navigable To make the `GridTile` component navigable via keyboard or gamepad, you can use the Navigation component. There are two ways to achieve this. ##### The Declarative Approach You can use the Navigation.Area component to wrap your tiles, but you are required to use the `selector` prop. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid-tile/#guide] ## GridTile: Guide (2/3) 1. Assign a specific class name to your `GridTile` components. 2. Pass that exact same class (without the dot) to the selector prop of the `Navigation.Area`. ```tsx import Navigation from '@components/Utility/Navigation/Navigation'; import Grid from '@components/Layout/Grid/Grid'; import GridTile from '@components/Layout/Grid/GridTile'; import Block from '@components/Layout/Block/Block'; import styles from './MyPage.module.scss'; const App = () => { return ( Item 1 Item 2 Item 3 ); }; ``` **Selector is Mandatory:** Unlike standard components, you cannot omit the selector prop for Grids. ##### Alternative: Manual Registration With Callback Ref You can manually register the tiles as a navigable area using the registerArea method. 1. Wrap the `Grid` (or a parent) with the `Navigation` component. 2. Use the `ref` callback to access the `Navigation` API immediately. 3. Register the specific class name of your list items using `registerArea`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid-tile/#guide] ## GridTile: Guide (3/3) ```tsx import Navigation, { NavigationRef } from '@components/Utility/Navigation/Navigation'; const App = () => { const handleNavReady = (api: NavigationRef) => { // Manually register the class used on the tiles api.registerArea('grid-area', ['.my-grid-tile'], true); }; return ( ... ... ); } ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid/] ## Grid The `Grid` component is a flexible, dynamic container that arranges content in a structured grid layout. It provides a mechanism for creating interactive grids where individual cells can be updated dynamically. The `Grid` component must be used in tandem with the GridTile component, which allows for placement of content within specific grid cells. **Tile Slot Support:** From Gameface UI version 2.1 onwards, you can access the `GridTile` component as a slot of the `Grid` component, using `Grid.Tile`. The previous method of importing `GridTile` separately is still supported for backward compatibility. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid/#installation] ## Grid: Installation Every component ships with the boilerplate. If you are working in your own project, add `Grid` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Grid ``` The CLI pulls in whatever `Grid` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid/#usage] ## Grid: Usage The `Grid` component must be provided with number of rows and columns through the `rows` and `cols` props. You can dynamically add or remove items in specific cells using the provided methods. **index.tsx:** ```tsx import Grid from '@components/Layout/Grid/Grid'; import Block from '@components/Layout/Block/Block'; Placed in row 2 column 2 Placed in row 3 column 2 Placed in row 3 column 3 ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid/#api] ## Grid: API (1/2) #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `GridRef` | `undefined` | Retrieves the grid’s properties, methods and HTML element and assigns them to a local variable `rows` | `number` | `Required` | The number of rows in the grid. `cols` | `number` | `Required` | The number of columns in the grid. `gap` | `string` | `undefined` | Applies spacing between the rows and columns. It’s a shorthand for both row and column gaps. Requires Gameface 2.2+. `row-gap` | `string` | `undefined` | Vertical spacing between grid rows. Requires Gameface 2.2+. `column-gap` | `string` | `undefined` | Horizontal spacing between grid columns. Requires Gameface 2.2+. `row-class` | `string` | `""` | Additional CSS classes for internal row wrappers. `column-class` | `string` | `""` | Additional CSS classes for internal column/cell wrappers. `row-style` | `JSX.CSSProperties` | `{}` | Inline styles applied to internal row wrappers. `column-style` | `JSX.CSSProperties` | `{}` | Inline styles applied to internal column/cell wrappers. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid/#api] ## Grid: API (2/2) Prop Name | Type | Default | Description `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. **Note on Compatibility:** The gap properties require Gameface version 2.2 or higher. If using an older version, these properties will be ignored. Check the console for compatibility warnings. #### Methods Method | Parameters | Return Value | Description `addItem` | `row`: number, `col`: number, `item`: JSX.Element | `void` | Adds the provided element to the specified row and column. Will throw an error if the row and column don’t exist. Will overwrite any existing items to the specified row and column. `removeItem` | `row`: number, `col`: number | `void` | Removes the content of the specified cell. Will throw an error if the row and column don’t exist. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid/#slots] ## Grid: Slots (1/2) #### Grid.Tile The `Tile` slot is used to specify on which row and column the content inside it should be placed on the Grid. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `GridTileRef` | `undefined` | Retrieves the `GridTile`’s properties, methods and HTML element and assigns them to a local variable `row` | `number` | `Required` | The row index where the tile will be placed. `col` | `number` | `Required` | The column index where the tile will be placed. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. ##### Methods Method | Parameters | Return Value | Description `moveTile` | `newRow`: number, `newCol`: number | `void` | Moves the tile to a different place on the grid. Will throw an error if the row and column don’t exist. `removeItem` | `void` | `void` | Removes the tile from the grid. Will throw an error if the row and column don’t exist. `replaceTile` | `newTile`: JSX.ELement | `void` | Inserts new content on the place of the tile. Will throw an error if the row and column don’t exist. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid/#slots] ## Grid: Slots (2/2) **Tip:** You can check more in-depth usage examples of the `Grid.Tile` slot in the GridTile documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/grid/#guide] ## Grid: Guide #### Dynamically Updating Grid Cells The `Grid` component provides methods to dynamically add or remove items from specific grid cells. These methods can be accessed via the `ref` prop. The steps to achieve it are as follows: 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `GridRef`, which you need to import 3. Set the declared variable as the value of the `ref` prop of the `Grid` component 4. Call the methods from the `ref` ##### Example ```tsx import Grid { GridRef } from '@components/Layout/Grid/Grid'; import GridTile from '@components/Layout/GridTile/GridTile'; import Block from '@components/Layout/Block/Block'; const App = () => { let gridRef!: GridRef; const addNewGridItem = () => { const newBlock = (New) gridRef.addItem(1, 1, newBlock); } const removeGridItem = () => { gridRef.removeItem(1, 1); } return ( Placed in row 2 column 2 Placed in row 3 column 2 Placed in row 3 column 3 Add Item Remove Item ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/layout-3d/] ## Layout3D The `Layout3D` component is a structural element designed to act as a container for 3D transformations. It sets up a 3D scene by defining a `distance` property, which controls the perspective. This perspective determines how far the user is from the z-plane of the 3D scene, affecting how 3D transformations appear. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/layout-3d/#installation] ## Layout3D: Installation Every component ships with the boilerplate. If you are working in your own project, add `Layout3D` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Layout3D ``` The CLI pulls in whatever `Layout3D` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/layout-3d/#usage] ## Layout3D: Usage The default use case for the `Layout` component is as a container for 3D scenes. It pairs seamlessly with the `Transform` component to apply 3D transformations. **index.tsx:** ```tsx import Layout3D from '@components/Layout/Layout3D/Layout3D'; import Transform from '@components/Layout/Transform/Transform'; Element rotated by 60° on the y-axis. ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/layout-3d/#api] ## Layout3D: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `distance` | `string` | `0` | Defines the perspective distance (z-plane to user). Use valid CSS unit values (e.g., `px`, `em`, `%`). `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/layout-3d/#guide] ## Layout3D: Guide (1/2) #### Setting Up a 3D Scene The `Layout3D` component is the foundational container for 3D scenes. By specifying the `distance` prop, you control the perspective effect. Combine it with the `Transform` component to achieve dynamic 3D transformations. ```tsx import Layout3D from '@components/Layout/Layout3D/Layout3D'; import Transform from '@components/Layout/Transform/Transform'; const App = () => { return ( Rotated by 45° on the y-axis and moved 200px away from the user. ); }; export default App; ``` #### Accessing the HTML element To access the HTML DOM element of the `Layout3D` component. 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `Layout3D` component ##### Example --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/layout-3d/#guide] ## Layout3D: Guide (2/2) ```tsx import Layout3D from '@components/Layout/Layout3D/Layout3D'; import Transform from '@components/Layout/Transform/Transform'; const App = () => { let layout3DRef!: HTMLDivElement return ( Element scaled by 2 by the x and y axes and translated towards the user by 150px. ); }; export default App; ``` Now you can access the HTML element of `Layout3D` with `layout3DRef` and make modifications to it if needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/layout/] ## Layout The `Layout` component is a structural element designed to act as a page container in your application. The `Layout` component is meant to be used as a general top-level wrapper of your page. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/layout/#installation] ## Layout: Installation Every component ships with the boilerplate. If you are working in your own project, add `Layout` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Layout ``` The CLI pulls in whatever `Layout` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/layout/#usage] ## Layout: Usage The default use case for the `Layout` component is as a container for major sections of your app, such as the main content area or an overall page layout wrapper. **index.tsx:** ```tsx import Layout from '@components/Layout/Layout/Layout'; import Top from '@components/Layout/Top/Top'; import Content from '@components/Layout/Content/Content'; import Bottom from '@components/Layout/Bottom/Bottom'; Top Section Main Content Bottom Section ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/layout/#api] ## Layout: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/layout/#slots] ## Layout: Slots 3.0.0 #### Top, Content, Bottom The `Top`, `Content`, and `Bottom` slots structure the internal layout of the `Layout` component. They clearly define which content belongs in the top, main, and bottom sections of your page or container. **Note on Slot Usage:** These slots provide a convenient, dot-notation syntax for the Top, Content, and Bottom components as children of `Layout`. You can still import and use those components separately if you prefer. ##### Usage ```tsx import Layout from '@components/Layout/Layout/Layout'; import Top from '@components/Layout/Top/Top'; import Content from '@components/Layout/Content/Content'; import Bottom from '@components/Layout/Bottom/Bottom'; const App = () => { return ( Top Section Main Content Bottom Section ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/layout/#guide] ## Layout: Guide #### Accessing the HTML element To access the HTML DOM element of the `Layout` component. 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `Layout` component ##### Example ```tsx import Layout from '@components/Layout/Layout/Layout'; import Top from '@components/Layout/Top/Top'; import Content from '@components/Layout/Content/Content'; import Bottom from '@components/Layout/Bottom/Bottom'; const App = () => { let layoutRef!: HTMLDivElement return ( Top Section Main Content Bottom Section ); }; ``` Now you can access the HTML element of `Layout` with `layoutRef` and make modifications to it if needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/list/] ## List The `List` component displays structured content as a vertical stack of items. It supports unordered and ordered formats, automatic nesting, and configurable bullets. Each item also exposes an inline Icon slot so you can override the bullet/icon for that specific item. It’s ideal for UI elements like settings menus, objectives, inventories, or any structured group of interactive or static content. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/list/#installation] ## List: Installation Every component ships with the boilerplate. If you are working in your own project, add `List` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add List ``` The CLI pulls in whatever `List` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/list/#usage] ## List: Usage To use `List`, wrap `List.Item` components inside the `List`. You can optionally specify the list type (unordered or ordered) and set the bullet style for the list with the `bullet-type` prop, or override it per item by placing `List.Icon` inside that item. **index.tsx:** ```tsx import List from '@components/Layout/List/List'; import starIcon from '@assets/icons/round-star.svg'; const App = () => { return ( Step one Step two Step 2.1 Step 2.2 Special step ); }; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/list/#api] ## List: API #### Props Prop Name | Type | Default | Description `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `type` | `'ordered' \| 'unordered'` | `'unordered'` | Controls whether the list is ordered (numbered) or unordered (bulleted). Automatically set to `'ordered'` when `bullet-type` is `"number"`. `bullet-type` | `'disc' \| 'circle' \| 'square' \| 'number' \| 'none' \| string \| ImageMetadata` | `'disc'` (unordered) / `'number'` (ordered) | Sets the bullet style for all items in the list. Can be a predefined style, or an image. `bullet-class` | `string` | `""` | Additional CSS classes to apply to all bullet elements. `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply to the root element. `class` | `string` | `""` | Additional CSS classes to apply to the root element. `children` | `JSX.Element` | `""` | List items to render. It renders only `List.Item` components. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/list/#slots] ## List: Slots (1/3) #### List.Item Use `List.Item` to define an item in the list. Items can contain any valid JSX content, including nested `List` components. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles for the individual list item. `class` | `string` | `""` | Additional CSS classes for the item. `children` | `JSX.Element` | `""` | Content of the list item. Supports nested `List` components and any other valid JSX content. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. ##### Usage ```tsx import List from '@components/Layout/List/List'; const App = () => { return ( Start the game
Adjust settings
Graphics Sound
Exit
); }; ``` **Caution:** You can only nest a `List` inside a `List.Item`.\ Placing a `List` directly inside another `List` without wrapping it in a `List.Item` is not supported. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/list/#slots] ## List: Slots (2/3) **Caution:** If a `List.Item` contains **only** a nested `List` (no other text or content),\ its bullet will still be rendered.\ To remove it, hide the `List.Icon` manually: ```tsx Graphics ``` #### List.Icon The `List.Icon` slot lets you override the bullet for **one specific item**.\ It does **not** affect other items in the list. - **`bullet-type`** and **`bullet-class`** (props on `List`) set the default bullet for **all items**. - If you add `class` or `style` directly to `List.Icon`, those styles override the defaults for **that item only**. - If you provide children inside `List.Icon`, they replace the bullet entirely for that item (text, SVG, custom JSX, etc.). ##### Usage ```tsx import List from '@components/Layout/List/List'; import SwordIcon from '@assets/icons/sword.svg?component-solid'; const App = () => { return ( Default bullet Custom styled bullet Fully custom icon ); }; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/list/#slots] ## List: Slots (3/3) Prop Name | Type | Default | Description `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `class` | `string` | `""` | Additional CSS classes for **this icon only**. Overrides `bullet-class` from `List` for this item. `style` | `JSX.CSSProperties` | `{}` | Inline styles for **this icon only**. Overrides styles from `List` for this item. `children` | `JSX.Element` | `""` | Custom content to replace the bullet entirely for this item. If set, `bullet-type` and `bullet-class` are ignored. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/list/#guide] ## List: Guide (1/5) #### Nesting list items The `List` component supports automatic styling for nested items. When you nest one `List` inside a `List.Item`, indentation adjust accordingly. ```tsx import List from '@components/Layout/List/List'; const App = () => { return ( Main Quest Side Quests Rescue the merchant Find the lost ring ); }; ``` #### Rendering list items dynamically To dynamically render list items in the `List` component, you can use an array and map over it: ```tsx import List from '@components/Layout/List/List'; const items = [ { id: 1, text: 'Start mission' }, { id: 2, text: 'Collect 5 herbs' }, { id: 3, text: 'Return to base' } ]; const App = () => { return ( {items.map((item) => ( {item.text} ))} ); }; ``` Alternatively, you can use the SolidJS `` component: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/list/#guide] ## List: Guide (2/5) ```tsx import List from '@components/Layout/List/List'; import { For } from 'solid-js'; const items = [ { id: 1, text: 'Start mission' }, { id: 2, text: 'Collect 5 herbs' }, { id: 3, text: 'Return to base' } ]; const App = () => { return ( {(item) => ( {item.text} )} ); }; ``` #### Setting custom image for list bullets To change all bullets of the `List` with a custom image, import the image and pass it to the `bullet-type` prop: ```tsx import List from '@components/Layout/List/List'; import QuestArrow from 'assets@/quest-arrow.svg'; const App = () => { return ( Capture 3 fish Cook fish Eat fish ); }; ``` **Note:** When using a custom image, it will be applied as a `background-image` to every bullet in the list. To apply additional styles to all bullets at once, use the `bullet-class` prop and define your styles in the view’s `global.scss`. The class has to be global - a `*.module.scss` would hash the name and `bullet-class` would no longer match it: ```scss .custom-bullet-icon { background-color: yellow; } ``` Additionally, if you wish to change one of the icons in a list item, just provide it as a child in the `List.icon` slot. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/list/#guide] ## List: Guide (3/5) ```tsx import List from '@components/Layout/List/List'; import QuestArrow from 'assets@/quest-arrow.svg'; import QuestArrow2 from 'assets@/quest-arrow2.svg?component-svg'; import 'index.css' const App = () => { return ( Capture 3 fish Cook fish ); }; ``` #### Accessing the HTML element To access the HTML DOM element of the `List` component. 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `List` component ##### Example ```tsx import List from '@components/Layout/List/List'; const App = () => { let listRef!: HTMLDivElement return ( Main Quest Side Quest ); }; ``` **Note:** You can access the element of every `List.Item` component in the same way. Now you can access the HTML element of `List` with `listRef` and make modifications to it if needed. #### Making list items navigable To make the `List` component navigable via keyboard or gamepad, you can use the Navigation component. There are two ways to achieve this. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/list/#guide] ## List: Guide (4/5) ##### Approach 1: The Callback Ref You can manually register the list items using the registerArea method. 1. Wrap the `List` (or a parent) with the `Navigation` component. 2. Use the `ref` callback to access the `Navigation` API immediately. 3. Register the specific class name of your list items using `registerArea`. ```tsx import List from '@components/Layout/List/List'; import Navigation, {NavigationRef} from '@components/Utility/Navigation/Navigation'; import { For } from 'solid-js'; const App = () => { // 1. Use a callback to register the area immediately when Navigation initializes const handleNavRef = (api: NavigationRef) => { // Note the dot (.) prefix for the class selector api.registerArea('list-items', ['.test'], true); }; return ( {(item) => ( // 2. Add the matching class name to your items {item.text} )} ); } ``` ##### Approach 2: The Wrapper Component (Declarative) Alternatively, you can wrap the `List` in a Navigation.Area component. In this case, you must provide the `selector` prop to tell the area which inner elements are focusable. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/list/#guide] ## List: Guide (5/5) ```tsx import List from '@components/Layout/List/List'; import Navigation from '@components/Utility/Navigation/Navigation'; import For from 'solid-js'; const App = () => { return ( {(item) => ( // Add the matching class name to your items {item.text} )} ); } ``` **Selector Required:** When using `Navigation.Area` with a List, you must provide a valid class selector. If you omit the selector, the `Navigation` component will attempt to focus the direct children (the List wrapper itself), and your individual items will not be navigable. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/relative/] ## Relative The `Relative` component is a structural element designed to offset content or act as a **bounding box** for Absolute components. By applying offsets using the `top`, `left`, `right`, and `bottom` props, the `Relative` component allows precise positioning of nested content relative to its original position. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/relative/#installation] ## Relative: Installation Every component ships with the boilerplate. If you are working in your own project, add `Relative` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Relative ``` The CLI pulls in whatever `Relative` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/relative/#usage] ## Relative: Usage The primary use case for the `Relative` component is to offset nested content within the document structure or serve as a container for `Absolute` components. **index.tsx:** ```tsx import Relative from '@components/Layout/Relative/Relative'; import Block from '@components/Layout/Block/Block'; Content with top and right offset by 50px ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/relative/#api] ## Relative: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `top`, `left`, `right`, `bottom` | `string` | `""` | Specify the offset of the `Relative` component. It accepts any valid css unit value `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/relative/#guide] ## Relative: Guide (1/3) #### Offsetting content The `Relative` component’s position is controlled by its position props ( `top`, `left`, `right`, `bottom` ). Under the hood the component uses [CSS position](https://developer.mozilla.org/en-US/docs/Web/CSS/position) to offset the element. You can pass any valid CSS unit (e.g., `px`, `%`, `vh`, `em`) to these props to specify the directional offset of the component. ##### Example ```tsx import Relative from '@components/Layout/Relative/Relative'; import Block from '@components/Layout/Block/Block'; const App = () => { return ( Content with top offset of 15vh and right offset by 50px ); }; export default App; ``` **Important:** Since the `Relative` component uses `position: relative`, the offset applied is purely visual. The component remains part of the document flow, meaning that any subsequent content will still be positioned as if the `Relative` component occupies its original space. If you need to remove content from the document flow entirely (e.g., for tooltips, modals, or overlays), consider using the Absolute Component, which positions elements relative to their closest positioned ancestor or the viewport. #### Usage with the Absolute component --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/relative/#guide] ## Relative: Guide (2/3) One of the main purposes of the `Relative` component is to act as the **bounding box** for nested `Absolute` components. When an `Absolute` component is used within a `Relative` component, its position is calculated relative to the `Relative` component’s boundaries. This relationship ensures precise control over the placement of the `Absolute` component without affecting other elements on the page. ##### Example ```tsx import Relative from '@components/Layout/Relative/Relative'; import Absolute from '@components/Layout/Absolute/Absolute'; import Block from '@components/Layout/Block/Block'; const App = () => { return ( Normally positioned content This content is positioned 20px from the top and 40px from the left of the Relative container. Positioned at the bottom right corner of the Relative container. ); }; export default App; ``` #### Accessing the HTML element To access the HTML DOM element of the `Relative` component. 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `Relative` component ##### Example --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/relative/#guide] ## Relative: Guide (3/3) ```tsx import Relative from '@components/Layout/Relative/Relative'; import Block from '@components/Layout/Block/Block'; let relativeRef!: HTMLDivElement const App = () => { return ( Content with top and right offset by 50px ); }; export default App; ``` Now you can access the HTML element of `Relative` with `relativeRef` and make modifications to it if needed. #### Quickly centering an element within a container 3.0.0 The `center` prop of the `Absolute` component easily centers it within its closest relatively positioned ancestor. You can center it on both axes or restrict it to a single axis. This is particularly useful for quickly centering elements (like text) inside a container without manually calculating offsets. For example, to overlay text in the center of a `Progress.Bar`: 1. Wrap the `Progress.Bar` in a `Relative` component to establish a positioning context. 2. Place the `Absolute` component as a sibling to the `Progress.Bar`. 3. Set the `center` prop on the `Absolute` component to `true` (both axes), or specify `'x'` or `'y'` for a single axis. ```tsx 80% ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/row/] ## Row The `Row` component is a structural wrapper designed to be used to define a row in the layout where `Column` components will be used. It uses a flexbox-based layout system to create responsive rows of content. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/row/#installation] ## Row: Installation Every component ships with the boilerplate. If you are working in your own project, add `Row` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Row ``` The CLI pulls in whatever `Row` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/row/#usage] ## Row: Usage The primary use case for the `Row` component is as a container for `Column` components, enabling the creation of grid-like structures. **index.tsx:** ```tsx import Row from '@components/Layout/Row/Row'; import { Column2, Column10, Column12 } from '@components/Layout/Column/Column'; <> I take 2/12 of the row I take 10/12 of the row I take the full row ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/row/#api] ## Row: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/row/#guide] ## Row: Guide #### Creating a Grid Layout The `Row` component is designed to work seamlessly with `Column` components, where the `Row` acts as a horizontal container and the `Columns` define their widths. This makes it easy to create grid-like layouts for various use cases such as cards, forms, or responsive layouts. ##### Example ```tsx import Row from '@components/Layout/Row/Row'; import { Column2, Column10, Column12 } from '@components/Layout/Column/Column' const App = () => { return ( I take 2/12 of the row I take 10/12 of the row I take the full row ); }; export default App; ``` #### Accessing the HTML element To access the HTML DOM element of the `Row` component. 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `Row` component ##### Example ```tsx import Row from '@components/Layout/Row/Row'; import { Column } from '@components/Layout/Column/Column' const App = () => { let rowRef!: HTMLDivElement; return ( I take 2/12 of the row ); }; export default App; ``` Now you can access the HTML element of `Row` with `rowRef` and make modifications to it if needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/] ## Scroll The `Scroll` component is a container that automatically detects when its inner content is too big to fit within its set size. When this happens, it displays a scrollbar so that users can scroll through the content. This makes it ideal for displaying dynamic or lengthy information while keeping the layout neat. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#installation] ## Scroll: Installation Every component ships with the boilerplate. If you are working in your own project, add `Scroll` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Scroll ``` The CLI pulls in whatever `Scroll` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#usage] ## Scroll: Usage Wrap any content you want to make scrollable within the `Scroll` component. You can set a maximum width and height using inline styles or CSS classes. When the content inside the component grows larger than these dimensions, the component will show a scrollbar so users can navigate the hidden parts. **index.tsx:** ```tsx import Scroll from '@components/Layout/Scroll/Scroll' import Block from '@components/Layout/Block/Block'; import TextBlock from '@components/Basic/TextBlock/TextBlock'; I am a very long and dynamic text that can be scrolled - lorem Eaque, perspiciatis ad iusto expedita consectetur rerum tempora non nisi, porro tenetur repudiandae. Voluptatem magni dolore consequuntur officia nemo quidem minus. Possimus, quibusdam. ``` In this example, the text is wrapped inside the `Scroll` component, and the maximum dimensions are set to 200px by 200px. If the text is longer than that, a scrollbar appears so the user can scroll through the content. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#api] ## Scroll: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the scroll’s wrapper element. `class` | `string` | `""` | Additional CSS classes to apply to the scroll’s wrapper element. `ref` | `ScrollComponentRef \| undefined` | `undefined` | A reference to the component, providing access to its methods and the underlying HTML element. `onScroll` | `(event: { scrollDirection: 'up' \| 'down' }) => void` | `undefined` | A callback function triggered whenever the scroll position changes. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#ref-api] ## Scroll: Ref API To interact with the `Scroll` programmatically, you can use the `ScrollComponentRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Properties Property | Type | Description `element` | `HTMLDivElement` | A reference to the scroll’s root HTML element, useful for DOM access or styling. #### Methods Method | Parameters | Return Value | Description `scrollToElement` | `element: string \| HTMLElement` | `void` | Scrolls the container so the target element is aligned at the top of the scrollable area. The element must be part of the content inside the Scroll component. `scrollIntoView` | `element: string \| HTMLElement` | `void` | Scrolls just enough to ensure the element is fully visible within the scrollable area. The element must be part of the content inside the Scroll component. `scrollUp` | none | `void` | Scrolls the content upward by a fixed amount. `scrollDown` | none | `void` | Scrolls the content downward by a fixed amount. `begin` | none | `void` | Instantly scrolls the content to the very beginning (top). `end` | none | `void` | Instantly scrolls the content to the very end (bottom). --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#slots] ## Scroll: Slots (1/3) #### Scroll.Content **(Required)** Allows customization of the content within the `Scroll` component. This slot can be used to apply custom styles or include additional elements in the scrollable area. **Note:** This slot is required and must be used inside the `Scroll` component to define the scrollable content. ##### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the scrollable content. `class` | `string` | `""` | Additional CSS classes to style the scrollable content. `children` | `JSX.Element` | `undefined` | Content to render inside the scrollable area, which can be any valid JSX element. `ref` | `HTMLDivElement` | `undefined` | A reference to the scroll content wrapper HTML element, useful if you need to do custom calculations with the `scrollTop` or `scrollHeight` properties. ##### Usage ```tsx import Scroll from '@components/Layout/Scroll/Scroll' import Block from '@components/Layout/Block/Block'; const App = () => { return ( I am a very long and dynamic text that can be scrolled - lorem Eaque, perspiciatis ad iusto expedita consectetur rerum tempora non nisi, porro tenetur repudiandae. Voluptatem magni dolore consequuntur officia nemo quidem minus. Possimus, quibusdam. ); }; ``` #### Scroll.Bar --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#slots] ## Scroll: Slots (2/3) Allows customization of the scrollbar within the `Scroll` component. This slot can be used to apply custom styles or include additional elements in the scrollbar. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the scrollbar. `class` | `string` | `""` | Additional CSS classes to style the scrollbar. `children` | `JSX.Element` | `undefined` | Content to render inside the scrollbar, which can be any valid JSX element. ##### Usage ```tsx import Scroll from '@components/Layout/Scroll/Scroll' import Block from '@components/Layout/Block/Block'; const App = () => { return ( I am a very long and dynamic text that can be scrolled - lorem Eaque, perspiciatis ad iusto expedita consectetur rerum tempora non nisi, porro tenetur repudiandae. Voluptatem magni dolore consequuntur officia nemo quidem minus. Possimus, quibusdam. Custom Scroll Bar content ); }; ``` #### Scroll.Handle This slot allows you to customize the handle of the `Scroll` component. Use it to apply custom styles or include additional elements in the handle. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#slots] ## Scroll: Slots (3/3) **Note:** The `Scroll.Handle` slot is only rendered when used inside the `Scroll.Bar` slot. ##### Properties Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the scroll handle. `class` | `string` | `""` | Additional CSS classes to style the scroll handle. `children` | `JSX.Element` | `undefined` | Content to render inside the scroll handle, which can be any valid JSX element. ##### Usage ```tsx import Scroll from '@components/Layout/Scroll/Scroll' import Block from '@components/Layout/Block/Block'; const App = () => { return ( I am a very long and dynamic text that can be scrolled - lorem Eaque, perspiciatis ad iusto expedita consectetur rerum tempora non nisi, porro tenetur repudiandae. Voluptatem magni dolore consequuntur officia nemo quidem minus. Possimus, quibusdam. Custom Scroll Bar content ); }; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#implemented-navigation-actions] ## Scroll: Implemented Navigation Actions The `Scroll` component implements the following navigation actions by default: Action Name | Behavior `pan` | Scrolls the scrollable container up or down depending on stick position. You can extend the `Scroll` with additional navigation actions or override the default behavior using the `onAction` prop: ```tsx import Scroll from '@components/Layout/Scroll/Scroll'; console.log('Custom select logic'), 'pan': (_, axis: [number, number]) => console.log(`x: ${axis[0]}, y: ${axis[1]}`), // Overrides default }} > {/* Scrollable content goes here */} ``` For more information about navigation actions, see the Navigation component documentation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#guide] ## Scroll: Guide (1/6) #### Scrolling Programmatically The `Scroll` component lets you control the scrolling behavior through code. For example, you can programmatically scroll the content up or down by calling methods like `scrollUp()` and `scrollDown()`. These methods are accessed via a reference `(ref)` to the `Scroll` component. The steps to achieve it are as follows: 1. Declare a variable to hold the ref but don’t initialize it with a value. 2. The declared value should have a type of `ScrollComponentRef`, which you need to import. 3. Set the declared variable as the value of the `ref` prop of the `Scroll` component. 4. Call the methods from the `ref`. ##### Example --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#guide] ## Scroll: Guide (2/6) ```tsx import Scroll, { ScrollComponentRef } from '@components/Layout/Scroll/Scroll' import Button from '@components/Layout/Button/Button'; const App = () => { let scrollRef!: ScrollComponentRef; const scrollUp = () => { scrollRef.scrollUp(); } const scrollDown = () => { scrollRef.scrollDown() } return ( <> I am a very long and dynamic text that can be scrolled - lorem Eaque, perspiciatis ad iusto expedita consectetur rerum tempora non nisi, porro tenetur repudiandae. Voluptatem magni dolore consequuntur officia nemo quidem minus. Possimus, quibusdam. ); }; export default App; ``` #### Scrolling to a Specific Element The `Scroll` component also provides a method to automatically scroll to a particular element within its content. This is useful if you want to jump directly to a specific section, such as when a user clicks a button. The steps to achieve it are as follows: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#guide] ## Scroll: Guide (3/6) 1. Declare a variable to hold the ref but don’t initialize it with a value. 2. The declared value should have a type of `ScrollComponentRef`, which you need to import. 3. Set the declared variable as the value of the `ref` prop of the `Scroll` component. 4. Use the reference to call the `scrollToElement` method. Provide either a CSS selector `(string)` or an `HTMLElement` as the argument. The target element must be part of the content within the `Scroll` component. ##### Example --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#guide] ## Scroll: Guide (4/6) ```tsx import Scroll, { ScrollComponentRef } from '@components/Layout/Scroll/Scroll' import Button from '@components/Layout/Button/Button'; import Block from '@components/Layout/Block/Button'; const App = () => { let scrollRef!: ScrollComponentRef; const scrollToBlock = () => { // Here, we pass a string that matches the target element's class name. scrollRef.scrollToElement('.scroll-example'); } return ( <> I am a very long and dynamic text that can be scrolled - lorem Eaque, perspiciatis ad iusto expedita consectetur rerum tempora non nisi, porro tenetur repudiandae. Scroll to me Voluptatem magni dolore consequuntur officia nemo quidem minus. Possimus, quibusdam. ); }; export default App; ``` #### Execute Custom Logic When Scrolling Occurs You can provide an `onScroll` prop to the `Scroll` component to run your own code every time the component is scrolled. The `onScroll` handler receives an object containing useful information about the scroll event. Currently, this object includes: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#guide] ## Scroll: Guide (5/6) - `scrollDirection`: ‘up’ or ‘down’ – Indicates the direction in which the user is scrolling. Follow these steps to set it up: 1. **Create a Scroll Handler** - Write a function that will be called whenever a scroll event occurs. 2. **Import the Handler Type** - Import the `OnScrollHandler` type from the `Scroll` component. This ensures your handler has the correct function signature. 3. **Attach the Handler** - Pass your handler function to the `onScroll` prop of the `Scroll` component. ##### Example ```tsx import Scroll, { OnScrollHandler } from '@components/Layout/Scroll/Scroll' import Button from '@components/Layout/Button/Button'; import Block from '@components/Layout/Block/Button'; const App = () => { const handleScroll: OnScrollHandler = (scrollData) => { // Your logic console.log(scrollData.scrollDirection); // Will log the direction everytime scrolling occurs } return ( <> I am a very long and dynamic text that can be scrolled - lorem Eaque, perspiciatis ad iusto expedita consectetur rerum tempora non nisi, porro tenetur repudiandae. Voluptatem magni dolore consequuntur officia nemo quidem minus. Possimus, quibusdam. ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/scroll/#guide] ## Scroll: Guide (6/6) In this example, every time the user scrolls inside the `Scroll` component, the `handleScroll` function is executed. It receives an object that tells you whether the scroll direction is ‘up’ or ‘down’, allowing you to run additional custom logic as needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tab-link/] ## TabLink The `TabLink` component acts as a clickable trigger that changes the active tab. By providing a `location` prop that corresponds to a Tab’s `location`, clicking a `TabLink` updates the tab state in the `Tabs` context, thereby switching the displayed content. The `TabLink` component shouldn’t be used outside of the `Tabs` component. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tab-link/#installation] ## TabLink: Installation Every component ships with the boilerplate. If you are working in your own project, add `TabLink` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add TabLink ``` The CLI pulls in whatever `TabLink` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tab-link/#usage] ## TabLink: Usage To use the tab system, wrap your tab links and tab content with the `Tabs` component. Assign a unique `location` string to each Tab and its corresponding `TabLink`. Optionally, set a default tab using the `default` prop. ```tsx import Tabs from '@components/Layout/Tabs/Tabs' import Tabs from '@components/Layout/Tab/Tab' import TabLink from '@components/Layout/TabLink/TabLink' import Block from '@components/Layout/Block/Block'; import Flex from '@components/Layout/Flex/Flex'; import styles from './App.module.css'; const App = () => { return ( Local Online Local Multiplayer Online Multiplayer ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tab-link/#api] ## TabLink: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | A reference to the component that gives you access to the underlying HTML element. `location` | `string` | `undefined` | The target tab’s identifier. This value must match the `location` prop of a corresponding `Tab` component. When clicked, the `TabLink` updates the active tab state in the `Tabs` component, making the associated `Tab` visible. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tab/] ## Tab The `Tab` component conditionally renders its content based on the active tab state managed by the parent `Tabs` component. Each `Tab` is assigned a unique `location` prop, and only the `Tab` whose location matches the currently active tab will display its content. The `Tab` component shouldn’t be used outside of the `Tabs` component. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tab/#installation] ## Tab: Installation Every component ships with the boilerplate. If you are working in your own project, add `Tab` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Tab ``` The CLI pulls in whatever `Tab` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tab/#usage] ## Tab: Usage To use the tab system, wrap your tab links and tab content with the `Tabs` component. Assign a unique `location` string to each Tab and its corresponding `TabLink`. Optionally, set a default tab using the `default` prop. ```tsx import Tabs from '@components/Layout/Tabs/Tabs' import Tabs from '@components/Layout/Tab/Tab' import TabLink from '@components/Layout/TabLink/TabLink' import Block from '@components/Layout/Block/Block'; import Flex from '@components/Layout/Flex/Flex'; import styles from './App.module.css'; const App = () => { return ( Local Online Local Multiplayer Online Multiplayer ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tab/#api] ## Tab: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | A reference to the component that gives you access to the underlying HTML element. `location` | `string` | `undefined` | A unique identifier for the tab. This value must match the `location` prop of a corresponding `TabLink` component to correctly associate the tab with its trigger. Only the `Tab` with a `location` matching the active tab state in the `Tabs` component will be displayed. `keepInMemory` | `boolean` | `false` | A `boolean` flag specifying whether the content of the Tab should be preserved in memory. Use this option if you want to improve scripting performance at the cost of increased memory usage and initial load time. Keep in mind that when this option is set to true, the content of the Tab will be initialized in memory upon component mount, even if the Tab is never rendered. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tab/#guide] ## Tab: Guide #### Store Tab content in memory If you want to optimize tab switching and reduce scripting time, you can enable the `keepInMemory` flag for individual tabs. This ensures that the `Tab`’s children are stored in memory upon component mount, regardless of whether the `Tab` has been rendered. This is especially useful if the `Tab` contains complex components. ##### Example ```tsx import Tabs from '@components/Layout/Tabs/Tabs' import Tabs from '@components/Layout/Tab/Tab' import TabLink from '@components/Layout/TabLink/TabLink' import Block from '@components/Layout/Block/Block'; import Flex from '@components/Layout/Flex/Flex'; import styles from './App.module.css'; const App = () => { return ( Local Online Local Multiplayer Online Multiplayer ); }; export default App; ``` In this example, both the “Local” and “Online” multiplayer tabs will be kept in memory, allowing for faster switching between them. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tabs/] ## Tabs The `Tabs` component provides tab-switching functionality by using a context to manage state. It works in conjunction with two child components: - `Tab`: Wraps the content of each tab and displays it only when its associated tab is active. - `TabLink`: Renders a clickable element that switches the active tab when clicked. You can also nest Tabs or generate them dynamically, and you can run custom logic before or after a tab change. **Note:** The `Tabs` component does not render an HTML element. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tabs/#installation] ## Tabs: Installation Every component ships with the boilerplate. If you are working in your own project, add `Tabs` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Tabs ``` The CLI pulls in whatever `Tabs` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tabs/#usage] ## Tabs: Usage To use the tab system, wrap your tab links and tab content with the `Tabs` component. Assign a unique `location` string to each Tab and its corresponding `TabLink`. Optionally, set a default tab using the `default` prop. ```tsx import Tabs from '@components/Layout/Tabs/Tabs' import Tabs from '@components/Layout/Tab/Tab' import TabLink from '@components/Layout/TabLink/TabLink' import Block from '@components/Layout/Block/Block'; import Flex from '@components/Layout/Flex/Flex'; import styles from './App.module.css'; const App = () => { return ( Local Online Local Multiplayer Online Multiplayer ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tabs/#api] ## Tabs: API #### Props Prop Name | Type | Default | Description `default` | `string` | `undefined` | Specifies the default active tab. The value must match the location of one of the `Tab` components. `ref` | `TabsComponentRef` | `undefined` | A reference to the component that gives you access to its methods (e.g., to switch tabs from your code). `onBeforeTabChange` | `async (currentLocation: string, newLocation: string) => Promise \| void \| boolean \| undefined` | `undefined \| boolean` | Callback invoked right before the Tab changes. It receives the current and next location before the change. Return `false` in the callback to prevent the tab from changing `onTabChanged` | `async (newLocation?: string) => void` | `undefined` | Callback invoked right after the Tab changes. It receives the new location after the change. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tabs/#ref-api] ## Tabs: Ref API To interact with the `Tabs` programmatically, you can use the `TabsComponentRef` interface. This interface provides properties and methods to access and manipulate the component’s state. #### Methods Method | Parameters | Return Value | Description `changeTab` | `newTab: string` | `void` | Switches the active tab programmatically. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tabs/#guide] ## Tabs: Guide (1/7) #### Changing active tab Programmatically You can change tabs via code by using the `changeTab` method exposed through a component reference. Here’s how: 1. Declare a variable to hold the ref but don’t initialize it with a value. 2. The declared value should have a type of `TabsComponentRef`, which you need to import. 3. Set the declared variable as the value of the `ref` prop of the `Tabs` component. 4. Call the `changeTab` method from the `ref`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tabs/#guide] ## Tabs: Guide (2/7) ```tsx import Tabs, { TabsComponentRef } from '@components/Layout/Tabs/Tabs' import Button from '@components/Layout/Button/Button'; import Tabs from '@components/Layout/Tabs/Tabs' import Tabs from '@components/Layout/Tab/Tab' import TabLink from '@components/Layout/TabLink/TabLink' import Block from '@components/Layout/Block/Block'; import Flex from '@components/Layout/Flex/Flex'; const App = () => { let tabsRef!: TabsComponentRef; const goToTab = () => { // Programmatically change the active tab. tabsRef.changeTab('Online'); }; return ( <> Local Online Local Multiplayer Online Multiplayer ); }; export default App; ``` #### Nested Tabs You can nest `Tabs` inside a `Tab` component to create sub-tabs for more complex UIs. ##### Example --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tabs/#guide] ## Tabs: Guide (3/7) ```tsx import Tabs from '@components/Layout/Tabs/Tabs' import Tabs from '@components/Layout/Tab/Tab' import TabLink from '@components/Layout/TabLink/TabLink' import Block from '@components/Layout/Block/Block'; import Flex from '@components/Layout/Flex/Flex'; const App = () => { return ( Local Online Local Multiplayer Online Multiplayer Casual Competetive Casual Multiplayer Competetive Multiplayer ); }; export default App; ``` In this example the content inside the ‘Online Multiplayer’ `Tab` has a subsection which can lead the user in either casual or competetive multiplayer. #### Dynamic Tabs --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tabs/#guide] ## Tabs: Guide (4/7) You can dynamically generate tabs by mapping over an array for example and rendering `TabLink` and `Tab` components with matching location props. ##### Example ```tsx import Tabs from '@components/Layout/Tabs/Tabs' import Tabs from '@components/Layout/Tab/Tab' import TabLink from '@components/Layout/TabLink/TabLink' import Block from '@components/Layout/Block/Block'; import Flex from '@components/Layout/Flex/Flex'; const App = () => { const array = Array.from({ length: 10 }, (_, index) => index); return ( {(element, i) => <> {element} tab {i()} } ); }; export default App; ``` In this example we are dynamically generating 10 different `TabLink` and `Tab` components with the `location` prop being generated dynamically as well! #### Executing logic before or after tab change You can run custom logic just before or after a tab change by supplying callbacks via the `onBeforeTabChange` and `onTabChanged` props. - `onBeforeTabChange`: Called right before the tab changes. - `onTabChanged`: Called immediately after the tab changes. These functions can be both synchronous or asynchronous. ##### Example (Synchronous) --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tabs/#guide] ## Tabs: Guide (5/7) ```tsx import Tabs from '@components/Layout/Tabs/Tabs' import Tabs from '@components/Layout/Tab/Tab' import TabLink from '@components/Layout/TabLink/TabLink' import Block from '@components/Layout/Block/Block'; import Flex from '@components/Layout/Flex/Flex'; const App = () => { const beforeTabChanged = (currentLocation?: string) => { console.log(`Location before change: ${currentLocation}`) } const afterTabChanged = (newLocation?: string) => { console.log(`Location after change: ${newLocation}`) } return ( Local Online Local Multiplayer Online Multiplayer ); }; export default App; ``` With this setup, if you change the Tabs back and forth by clicking on the `TabLink` elements, you will see log messages such as: ```log Location before change: Local Location after change: Online Location before change: Online Location after change: Local ``` ##### Example (Asynchronous) --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tabs/#guide] ## Tabs: Guide (6/7) With the `onBeforeTabChange` and `onTabChanged` props you can run asynchronous logic such as fetching data from the server before or after a tab has changed. To do so, you need to provide an async function as callback. ```tsx import Tabs from '@components/Layout/Tabs/Tabs' import Tabs from '@components/Layout/Tab/Tab' import TabLink from '@components/Layout/TabLink/TabLink' import Block from '@components/Layout/Block/Block'; import Flex from '@components/Layout/Flex/Flex'; const App = () => { const beforeTabChanged = async (currentLocation: string, newLocation: string) => { console.log(`Location before change: ${currentLocation}`) // Simulate fetching data or another async operation await new Promise((resolve) => setTimeout(resolve, 1000)); console.log('Data fatched!') } const afterTabChanged = (newLocation?: string) => { console.log(`Location after change: ${newLocation}`) } return ( Local Online Local Multiplayer Online Multiplayer ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/tabs/#guide] ## Tabs: Guide (7/7) With this setup, if you change the Tabs back and forth by clicking on the `TabLink` elements, you will see log messages such as: ```log Location before change: Local Data fatched! Location after change: Online Location before change: Online Data fatched! Location after change: Local ``` #### Preventing a tab change Use `onBeforeTabChange` to prevent a switch. If the callback returns false, the change is canceled. The handler receives the current and the next tab locations. ##### Example: block switching to the “Online” tab. ```tsx import Tabs from '@components/Layout/Tabs/Tabs' import Tabs from '@components/Layout/Tab/Tab' import TabLink from '@components/Layout/TabLink/TabLink' import Flex from '@components/Layout/Flex/Flex'; const App = () => { const beforeTabChanged = (currentLocation: string, newLocation: string) => { if (newLocation === "Online") return false } return ( Local Online Local Multiplayer Online Multiplayer ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/top/] ## Top The `Top` component is a structural element designed to act as a wrapper of the top-level elements in your page. The `Top` component is meant to be used as a wrapper of your top menus, navigation bars, etc. Typically, the `Top` component is used alongside the `Content` and `Bottom` components to achieve better page structure. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/top/#installation] ## Top: Installation Every component ships with the boilerplate. If you are working in your own project, add `Top` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Top ``` The CLI pulls in whatever `Top` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/top/#usage] ## Top: Usage The primary use case for the `Top` component is as a top level section container. **index.tsx:** ```tsx import Layout from '@components/Layout/Layout/Layout'; import Top from '@components/Layout/Top/Top'; import Content from '@components/Layout/Content/Content'; import Bottom from '@components/Layout/Bottom/Bottom'; Top Menu Main Content Bottom Section ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/top/#api] ## Top: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `basis` | `number` | `15%` | Sets the flex-basis of the component as a percentage. For example, a value of `30` sets the flex-basis to `30%`. `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/top/#guide] ## Top: Guide #### Accessing the HTML element To access the HTML DOM element of the `Top` component. 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `Top` component ##### Example ```tsx import Layout from '@components/Layout/Layout/Layout'; import Top from '@components/Layout/Top/Top'; import Content from '@components/Layout/Content/Content'; import Bottom from '@components/Layout/Bottom/Bottom'; const App = () => { let topRef!: HTMLDivElement return ( Top Section Main Content Bottom Section ); }; ``` Now you can access the HTML element of `Top` with `topRef` and make modifications to it if needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/transform/] ## Transform The `Transform` component is a versatile utility component designed for applying CSS transformations such as `translate`, `rotate`, `scale`, and `skew`. It also allows you to define a `transform-origin`, specifying the point from which transformations originate. The `Transform` component is ideal for creating dynamic visual effects, animations, and 3D interactions. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/transform/#installation] ## Transform: Installation Every component ships with the boilerplate. If you are working in your own project, add `Transform` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Transform ``` The CLI pulls in whatever `Transform` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/transform/#usage] ## Transform: Usage The `Transform` component can be used to apply individual `translate`, `rotate`, `scale`, or `skew` transformation or a combination of them with the `matrix` property. **index.tsx:** ```tsx import Content from '@components/Layout/Content/Content'; import Transform from '@components/Layout/Transform/Transform'; Rotated by 15°, originating from the top right corner of the element. Moved to the right by 15px, skewed by 15deg and increased the width and height of the element by 1.5 ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/transform/#api] ## Transform: API (1/2) #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `translate` | `{ x?: number; y?: number; z?: number; }` | `undefined` | Moves the element along the x, y, or z axis in `pixels`. For example, `{ x: 50 }` translates the element 50px to the right. `rotate` | `{ x?: number; y?: number; z?: number; }` | `undefined` | Rotates the element around the x, y, or z axis in `degrees`. For example, `{ z: 45 }` rotates the element 45° around the z-axis. `scale` | `{ x?: number; y?: number; z?: number; }` | `undefined` | Scales the element along the x, y, or z axis. For example, `{ x: 1.5 }` increases the width of the element by 50%. `skew` | `{ x?: number; y?: number; }` | `undefined` | Skews the element along the x or y axis in degrees. For example, `{ x: 15 }` skews the element 15° along the x-axis. `matrix` | `{ translate?: {...}; rotate?: {...}; scale?: {...}; skew?: {...}; }` | `undefined` | Defines a custom transformation matrix as a combination of multiple transformations. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/transform/#api] ## Transform: API (2/2) Prop Name | Type | Default | Description `origin` | `"top"`, `"center"`, `"bottom"`, `"right"`, `"left"`, `{ x?: string; y?: string; z?: string }` | `undefined` | Defines the `transform-origin` property, specifying the point of origin for transformations. It can accept preset values, combination of 2 values like: `top left`, `top right`, etc. or custom coordinates as an object (e.g., `{ x: '50%', y: '50%', z: '0' }`). `onAction` | `Record void>` | `undefined` | Allows you to add custom navigation action handlers to the component. See the Navigation component documentation for details. `anchor` | `string \| HTMLElement` | `undefined` | Links navigation to another element. When the anchor element is focused, this component’s actions will execute. Can be a CSS selector or HTMLElement. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/transform/#guide] ## Transform: Guide (1/3) #### Applying Transformations The Transform component lets you apply transformations such as `translation`, `rotation`, `scaling`, and `skewing`. These can be specified individually or combined using the matrix prop. Keep in mind that you must use the `matrix` property to apply 2 or more transformations at once. Otherwise only the transformations provided in the `matrix` property will evaluate. ```tsx import Layout3D from '@components/Layout/Layout3D/Layout3D'; import Content from '@components/Layout/Content/Content'; import Transform from '@components/Layout/Transform/Transform'; const App = () => { return ( Translated by 100px on the x axis and -50px away from the 3D scene. Moved to the right by 15px, skewed by 15deg and increased the width and height of the element by 1.5. ); }; export default App; ``` #### Changing the origin of transformation You can define an `origin` for transformations, specifying where the transformations originate. This can be set using presets like `center` or custom coordinates for more control --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/transform/#guide] ## Transform: Guide (2/3) ```tsx import Content from '@components/Layout/Content/Content'; import Transform from '@components/Layout/Transform/Transform'; const App = () => { return ( Rotated around the top-left corner ); }; export default App; ``` For more control: ```tsx import Content from '@components/Layout/Content/Content'; import Transform from '@components/Layout/Transform/Transform'; const App = () => { return ( Rotated around the top-left corner with 10% offset to the right ); }; export default App; ``` The second origin is almost the same as the first one, with the difference being that it starts 10% to the right from the top-left corner. #### Accessing the HTML element To access the HTML DOM element of the `Transform` component. 1. Declare a variable to hold the ref but don’t initialize it with a value 2. The declared value should have a type of `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `Transform` component ##### Example --- [SOURCE: https://gameface-ui.coherent-labs.com/components/layout/transform/#guide] ## Transform: Guide (3/3) ```tsx import Transform from '@components/Layout/Transform/Transform'; import Block from '@components/Layout/Block/Block'; const App = () => { let transformRef!: HTMLDivElement; return ( Element with translation ); }; export default App; ``` Now you can access the HTML element of `Transform` with `transformRef` and make modifications to it if needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/background-image/] ## BackgroundImage **Replaced by Image:** `BackgroundImage` has been removed from the boilerplate. `Image` accepts the same `src`, `fill` and `options` props and produces the same output, so the migration is a rename: ```diff ``` The one thing to check is a call site that passed **no** `options`, because `Image` defaults to 3.5rem square where `BackgroundImage` had no size of its own. See the `Image` docs and the migration guide. The `BackgroundImage` component allows you to create a container with an image as its background. It supports images in `.png`, `.jpg`, or `.svg` formats that can be imported directly from your assets folder. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/background-image/#installation] ## BackgroundImage: Installation Every component ships with the boilerplate. If you are working in your own project, add `BackgroundImage` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add BackgroundImage ``` The CLI pulls in whatever `BackgroundImage` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/background-image/#usage] ## BackgroundImage: Usage The `BackgroundImage` component is used to wrap other UI elements, applying a background image behind them. To use the component, import it and set the `src` attribute to a valid URL of the image to be used as the background. If no other `options` are specified, the background will be rendered with its original dimensions without repeating. Note that the background size is different from the container size. To set the dimensions of the `BackgroundImage` container, use either the `style` or `class` attributes. To set the background size inside the container, use the `size` property within the `options` object, for example, `options={{ size: 'contain' }}`. ```jsx import BackgroundImage from '@components/Media/BackgroundImage/BackgroundImage'; import Background from '@assets/bg.png'; const App = () => { return (
Content
); }; export default App; ``` In this example, the `BackgroundImage` component wraps the `
Content
` with a background image. The container has a width and height of `150px`. The `options` attribute sets the background image to fit inside the container, regardless of its original size. The background image source is specified by importing the image file via `import Background from '@assets/bg.png';`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/background-image/#api] ## BackgroundImage: API (1/2) #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `src` | `string` | `undefined` | The URL source of the background image. `fill` | `boolean` | `false` | Specifies if the component should fill its container by setting the `width` and `height` of the component to be 100%. `options` | `{ repeat?: ImageRepeat; size?: ImageSize; position?: ImagePosition; }` | `undefined` | Configures the background image. You can set whether the background repeats (default is no repeat), its size, and its position. For more information, check the options object properties. #### options object properties --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/background-image/#api] ## BackgroundImage: API (2/2) Prop Name | Accepted values | Default | Description `repeat` | `'both' \| 'x' \| 'y'` | None | Specifies whether the background image should repeat. By default, it does not repeat. If set to `both`, the background repeats on both the `x` and `y` axes. If set to `x`, it repeats on the `x` axis, and if set to `y`, it repeats on the `y` axis. `size` | `'contain' \| 'cover' \| any valid [background size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size) string` | None | By default, the background is rendered at its original size. This property can be used to adjust the size using `contain` or `cover` values, or any valid string for the `background-size` property. `position` | Any valid combination of `top`, `center`, `bottom`, `left`, `right` values or a valid [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position) string | None | Sets the position of the background image inside the container. The default is `top left`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/background-image/#guide] ## BackgroundImage: Guide (1/7) #### Loading an Image as Background To load an image as a background using the `BackgroundImage` component, import the component and set the `src` attribute to the image URL: ```jsx import BackgroundImage from '@components/Media/BackgroundImage/BackgroundImage'; import Background from '@assets/bg.png'; const App = () => { return (
Content
); }; export default App; ``` #### Setting the size of the background image container To set the size of the background image container, use either the `style` or `class` attributes. The following example demonstrates setting the `width` and `height` of the container to `150px` using the `style` attribute: ```jsx import BackgroundImage from '@components/Media/BackgroundImage/BackgroundImage'; import Background from '@assets/bg.png'; const App = () => { return (
Content
); }; export default App; ``` Since the `style` attribute is defined with an object, you can easily reuse this object across different `BackgroundImage` components if they need to have the same size. This pattern can also be used for the `options` attribute, as it also accepts an object value: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/background-image/#guide] ## BackgroundImage: Guide (2/7) ```jsx import { JSX } from 'solid-js'; import BackgroundImage from '@components/Media/BackgroundImage/BackgroundImage'; import Background from '@assets/bg.png'; const App = () => { const bgStyle: JSX.CSSProperties = { width: '150px', height: '150px' }; return (
Content 1
Content 2
); }; export default App; ``` However, if the styles of the component are static and will not change at runtime, it is recommended to use the `class` attribute for better performance: **App.module.css:** ```css .bg-image { width: 150px; height: 150px; } ``` ```jsx import BackgroundImage from '@components/Media/BackgroundImage/BackgroundImage'; import Background from '@assets/bg.png'; import styles from './App.module.css'; const App = () => { return (
Content
); }; export default App; ``` #### Setting the size of the background image --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/background-image/#guide] ## BackgroundImage: Guide (3/7) After setting the container size, you can define the background image size within it using the `options.size` property. This property accepts the strings `'contain'` or `'cover'`, or any valid string for the `background-size` CSS property, such as `100px 100px` or `100%`. For a complete list of valid values, refer to the [background-size documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size). The following example demonstrates two background image containers: one with the size set to `contain` and another with a custom size. ```jsx import { JSX } from 'solid-js'; import BackgroundImage from '@components/Media/BackgroundImage/BackgroundImage'; import Background from '@assets/bg.png'; const App = () => { const bgStyle: JSX.CSSProperties = { width: '150px', height: '150px' }; return (
Content 1
Content 2
); }; export default App; ``` In the second container, the background image will have a `width` and `height` of `100px`, making it smaller than the container’s `150px` dimensions. This ensures the entire image is visible within the container. #### Repeating the background image --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/background-image/#guide] ## BackgroundImage: Guide (4/7) By default, the `BackgroundImage` component renders the background image without repeating it. If the image is smaller than the container, only a single instance of the image will be shown. To change this behavior and repeat the background image, you can use the `options.repeat` property with one of the following values: 1. `'x'` - Repeat on the horizontal axis. 2. `'y'` - Repeat on the vertical axis. 3. `'both'` - Repeat on both axes. ```jsx import { JSX } from 'solid-js'; import { ImageBaseOptions } from '@components/Media/ImageBase/ImageBase'; import BackgroundImage from '@components/Media/BackgroundImage/BackgroundImage'; import Background from '@assets/bg.png'; const App = () => { const bgSize: ImageBaseOptions = { size: '100px 100px' }; const bgStyle: JSX.CSSProperties = { width: '150px', height: '150px' }; return (
Content 1
Content 2
Content 3
); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/background-image/#guide] ## BackgroundImage: Guide (5/7) Here, we also reused common options for all the `BackgroundImage` components by setting the `bgSize` variable. **Note** that it is preferred to set the type of `bgSize` to `ImageBaseOptions`. This allows you to take advantage of autocompletion for available options when using VSCode with the TypeScript plugin. #### Positioning the background image By default, the `BackgroundImage` component positions the image starting from the top-left edge of the container. You can change this behavior using the `options.position` property, which accepts any valid background position string. For more details, refer to the [background-position documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position). The following example demonstrates positioning the background using the `top`, `left`, `right`, `bottom` presets, and a custom value for the `position` option: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/background-image/#guide] ## BackgroundImage: Guide (6/7) ```jsx import { JSX } from 'solid-js'; import { ImageBaseOptions } from '@components/Media/ImageBase/ImageBase'; import BackgroundImage from '@components/Media/BackgroundImage/BackgroundImage'; import Background from '@assets/bg.png'; const App = () => { const bgSize: ImageBaseOptions = { size: '100px 100px' }; const bgStyle: JSX.CSSProperties = { width: '150px', height: '150px' }; return (
Content 1
Content 2
Content 3
); }; export default App; ``` #### Accessing the HTML element To access the HTML DOM element of the `BackgroundImage` component: 1. Declare a variable to hold the ref without initializing it. 2. The variable should be of type `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `BackgroundImage` component. ```tsx import BackgroundImage from '@components/Media/BackgroundImage/BackgroundImage'; import Background from '@assets/bg.png'; const App = () => { let ref!: HTMLDivElement; return (
Content
); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/background-image/#guide] ## BackgroundImage: Guide (7/7) You can now access the HTML element of `BackgroundImage` using `ref` and make modifications as needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/icon/] ## Icon **Replaced by Image:** `Icon` has been removed from the boilerplate. `Image` offers the same dot-path syntax over the whole `src/assets` folder: ```diff ``` `Icon` keys started at `src/assets/icons`, so an `icons.` segment appears at the front. Two behavioural differences: `Image` renders a `div` with a background rather than an ``, so there is no load-error fallback, but a mistyped path is now a build error instead of a missing image at runtime. See the migration guide. The `Icon` component provides a structured, auto-generated way to render your UI icons. Unlike standard images, it maps your `src/assets/icons` directory into a nested component tree, allowing you to access icons via dot notation. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/icon/#installation] ## Icon: Installation **Available in Gameface UI projects only:** `Icon` comes with the boilerplate and cannot be added to an existing project with the CLI. It depends on a generated type file and an icon-generation script that only exist in the full template, so an installed copy would not build. To use it, start from the boilerplate. The CLI documentation explains this in [components that need a full Gameface project](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/existing-projects/#components-that-need-a-full-gameface-project). --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/icon/#usage] ## Icon: Usage The `Icon` component eliminates the need to manually import image files. Instead, it exposes your folder structure directly as a component object. It works by scanning your `src/assets/icons` directory and generating a matching TypeScript definition. This means the component structure you use in code exactly mirrors your file system. - **Directorysrc/assets/icons/** - **Directorygamepad** - **Directoryxbox** - a.png - b.png - x.png - y.png - **Directoryui** - alert.png - check.png - close.png Because the component and types are auto-generated based on these files, you get full IntelliSense/Autocomplete support in your IDE. As you type `Icon.`, your editor will suggest the available folders and images (e.g., suggesting `gamepad` then `xbox` then `a`), preventing typos and invalid paths. The above folder structure would be accessed like this: ```tsx import { Icon } from '@components/Media/Icon/Icon'; const App = () => { return (
{/* Access icons directly via dot notation */}
); }; export default App; ``` The `Icon` component renders a standard `` element with the appropriate `src` attribute pointing to the image file. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/icon/#props] ## Icon: Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `fill` | `boolean` | `false` | Specifies if the component should fill its container by setting the `width` and `height` of the component to be 100%. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/icon/#guide] ## Icon: Guide (1/2) #### Adding New Icons We have added some predefined icons (in the `src/assets/icons` directory) to get you started, but you can easily add your own custom icons. To add a new icon to the component: 1. Drop the image file into `src/assets/icons/` (organize into subfolders as needed). 2. If you have an active development server, it should automatically detect the new file and typescript definitions will automatically update. If not, you can update the types manually by running the `npm run gen-icons` command in your terminal. 3. That’s it! The new icon will immediately be available to use within the `Icon` component and auto suggestions will appear in IntelliSense (e.g., ``). **Note:** It’s possible that you don’t see the new icon in Gameface immediately after adding it. If that happens, clear the cache (by pressing `ctrl + F5` in the Player) or restart the development server. **File names:** File and folder names are converted to camelCase, so separators and special characters are fine: `ui/hud icons/round-star.png` becomes ``. `-`, `_`, spaces and other punctuation may appear anywhere in the name and are collapsed away. Ignoring any leading separators, a name must start with an English letter (a-z) - `2x.png` and `---.png` fail `npm run gen-icons` with an error explaining how to rename them. Non-ASCII characters are stripped, so `über.png` becomes `ber`, and a name made only of them (`日本.png`) fails. #### Handling Missing Icons (Fallback) --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/icon/#guide] ## Icon: Guide (2/2) If an image in the icons directory that is referenced by the `Icon` components gets suddenly deleted or moved, the `Icon` component will automatically render a fallback placeholder icon instead of crashing your application. However, if you directly reference a non-existent icon (e.g., ``), your application will fail. It’s the same as trying to reference a non-existent component. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/image/] ## Image The `Image` component renders an image asset as the background of a `div`. Use the dot-path form for assets in `src/assets`: ```jsx import Image from '@components/Media/Image/Image'; const App = () => ; ``` With this approach, you don’t need to manually import the image, but you still benefit from path auto-completion and type checking while using the dot-path syntax. It is also the only format that can be packed into a texture atlas. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/image/#installation] ## Image: Installation **Available in Gameface UI projects only:** `Image` depends on the generated types file and the images plugin in `vite.config.mts`, so it is only available in the full template. To use it, start from the boilerplate. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/image/#usage] ## Image: Usage #### By path Every image under `src/assets` is exposed as a property of `Image`, matching the folder structure: ```jsx ``` This is the recommended form for project assets and for any image that may be packed into an atlas. #### By src Use `src` for anything outside `src/assets`, for runtime paths, and for SVGs: ```jsx import Image from '@components/Media/Image/Image'; import MyImage from '@assets/my-image.png'; const App = () => ; ``` **SVGs have no dot path:** Dot paths are generated exclusively for raster images (`.png`, `.jpg`, `.jpeg`, `.webp`). SVGs are not atlas-compatible, so please import them directly and pass them through `src`: ```jsx import MySvg from '@assets/my-svg.svg'; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/image/#api] ## Image: API #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles applied to the root element. `class` | `string` | `""` | CSS class names. `ref` | `HTMLDivElement` | `undefined` | DOM element reference. `src` | `string` | `undefined` | Asset source. Not needed for dot-path images. `fill` | `boolean` | `false` | Sets width and height to 100% of the parent. `options` | `{ repeat?, size?, position? }` | `undefined` | Controls how the image is drawn. #### options object properties Prop Name | Accepted values | Default | Description `repeat` | `'both' \| 'x' \| 'y'` | none | Repeat behavior. `size` | `'contain' \| 'cover'` or any valid background-size value | none | How the image is sized. `position` | `top`, `center`, `bottom`, `left`, `right`, or any valid background-position value | none | Where the image sits. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/image/#common-patterns] ## Image: Common patterns #### Default size Without `options`, `Image` defaults to a 3.5rem square and centers the image with `contain`. You can set your own size in the following way: ```jsx ``` #### Fill the container `fill` sets the component to 100% x 100% of its parent: ```jsx
``` #### Background mode When you pass `options`, `Image` behaves like a background image. It drops the default size and fills only the dimensions you give it: ```jsx
Content
``` **Background mode disables atlassing:** An image rendered with `options` is never packed into an atlas, because those CSS properties are exactly what the sprite needs. #### Runtime lookup A dot path can end in a computed key: ```jsx const key = () => currentGamepad(); ``` This pulls in the whole folder, because the build cannot know which key will run. If the project uses atlases, that can bloat the sheet. Keep these folders small or use an explicit map. ```jsx const glyphs = { a: Image.icons.gamepad.xbox.a, b: Image.icons.gamepad.xbox.b, }; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/image/#atlases] ## Image: Atlases Images written as `Image.folder.name` can be packed into texture atlases at build time. This reduces texture count and texture binds, and it lets the project preload a handful of sheet PNGs before a view opens. See Images and texture atlases for configuration and the build report. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/image/#limitations] ## Image: Limitations - `Image` can not be rendered inside a paragraph with `cohinline` enabled or `InlineTextBlock`; use a plain `` there. - `Image` is a `div` with a background, so it has no image error fallback. - SVGs are not exposed on `Image` and cannot be packed into a raster atlas. - Computed keys cost the whole folder. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/image/#migrating-from-icon-and-backgroundimage] ## Image: Migrating from Icon and BackgroundImage Both were deprecated in 5.0.0 and `Image` covers them. #### Icon `Icon` keys were relative to `src/assets/icons`; `Image` keys start at `src/assets`, so an `icons.` segment appears at the front. `Icon` rendered an `` with a fallback image on load error. `Image` renders a `div`, so there is no error event and no fallback, but a mistyped path is now a build error instead. ```diff ``` #### BackgroundImage The main behavior change is that `Image` has a 3.5rem default size unless you provide dimensions yourself. ```diff ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/live-view/] ## LiveView The `LiveView` component enables embedding dynamic textures rendered by the engine into the UI. **Note:** For more details on live views, refer to our documentations: - [Native](https://docs.coherent-labs.com/cpp-gameface/integration/optional_features/liveviews_native/) - [Unreal](https://docs.coherent-labs.com/unreal-gameface/advanced-features/texturesinui/liveviews/) - [Unity](https://docs.coherent-labs.com/unity-gameface/integration/optional_features/live_views_unity/) --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/live-view/#installation] ## LiveView: Installation Every component ships with the boilerplate. If you are working in your own project, add `LiveView` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add LiveView ``` The CLI pulls in whatever `LiveView` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/live-view/#usage] ## LiveView: Usage (1/2) To render a live view in your UI, use the `LiveView` component as shown below: ```jsx import LiveView from '@components/Media/LiveView/LiveView'; const App = () => { return ( ); }; export default App; ``` #### Styling the Component You can style the `LiveView` component using either the `class` or `style` attribute. For inline styles, pass an object with the desired properties. For example, you can set the `width` and `height` of the image as shown here. However, for better performance, it is recommended to use the `class` attribute. To do this, create a CSS file with the desired styles and apply them to the `LiveView` component: **MyLiveView.module.css:** ```css .my-live-view { width: 150px; height: 150px; } ``` ```jsx import LiveView from '@components/Media/LiveView/LiveView'; import styles from './MyLiveView.module.css'; const App = () => { return ( ); }; export default App; ``` #### Fill the container To make the `LiveView` component fill its container, set the `fill` property to `true`. This will apply styles to ensure the image occupies the entire space of its parent element. This prop is useful when you want the image to just adapt to the size of its container. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/live-view/#usage] ## LiveView: Usage (2/2) ```tsx import LiveView from '@components/Media/LiveView/LiveView'; import MyImage from '@assets/my-image.png'; const App = () => { return (
); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/mask-image/] ## MaskImage The `MaskImage` component allows you to create a container with an image that will be used as a mask layer over the content inside the component. It supports images in `.png`, `.jpg`, or `.svg` formats that can be imported directly from your assets folder. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/mask-image/#installation] ## MaskImage: Installation Every component ships with the boilerplate. If you are working in your own project, add `MaskImage` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add MaskImage ``` The CLI pulls in whatever `MaskImage` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/mask-image/#usage] ## MaskImage: Usage The `MaskImage` component is used to wrap other UI elements, masking them with an image. All the content inside the component will be visible in the colored area of the image. To use the component, import it and set the `src` attribute to a valid URL of the image to be used as a mask. If no other `options` are specified, the content will be masked with the original dimensions of the mask image without repeating it. Note that the mask size is different from the container size. To set the dimensions of the `MaskImage` container, use either the `style` or `class` attributes. To set the mask size, use the `size` property within the `options` object, for example, `options={{ size: 'contain' }}`. ```jsx import MaskImage from '@components/Media/MaskImage/MaskImage'; import Mask from '@assets/mask.png'; const App = () => { return (
Masked content
); }; export default App; ``` In this example, the `MaskImage` component wraps the `
Masked content
` and masks it with the image. The container has a width and height of `150px`. The `options` attribute sets the mask image to fit inside the container, regardless of its original size. The mask image source is specified by importing the image file via `import Mask from '@assets/mask.png';`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/mask-image/#api] ## MaskImage: API (1/2) #### Props Prop Name | Type | Default | Description `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. `ref` | `HTMLDivElement` | `undefined` | Retrieves the component’s DOM element and assigns it to a variable. `src` | `string` | `undefined` | The URL source of the mask image. `fill` | `boolean` | `false` | Specifies if the component should fill its container by setting the `width` and `height` of the component to be 100%. `options` | `{ repeat?: ImageRepeat; size?: ImageSize; position?: ImagePosition; }` | `undefined` | Configures the mask image. You can set whether the mask repeats (default is no repeat), its size, and its position. For more information, check the options object properties. #### options object properties --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/mask-image/#api] ## MaskImage: API (2/2) Prop Name | Accepted values | Default | Description `repeat` | `'both' \| 'x' \| 'y'` | None | Specifies whether the mask image should repeat. By default, it does not repeat. If set to `both`, the mask repeats on both the `x` and `y` axes. If set to `x`, it repeats on the `x` axis, and if set to `y`, it repeats on the `y` axis. `size` | `'contain'` \| `'cover'` \| any valid [mask size](https://developer.mozilla.org/en-US/docs/Web/CSS/mask-size) string | None | By default, the mask image is rendered at its original size. This property can be used to adjust the size using `contain` or `cover` values, or any valid string for the `mask-size` property. `position` | Any valid combination of `top`, `center`, `bottom`, `left`, `right` values or a valid [mask-position](https://developer.mozilla.org/en-US/docs/Web/CSS/mask-position) string | None | Sets the position of the mask image inside the container. The default is `top left`. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/mask-image/#guide] ## MaskImage: Guide (1/6) #### Loading an image as a mask To use an image as a mask with the `MaskImage` component, import the component and set the `src` attribute to the image URL: ```jsx import MaskImage from '@components/Media/MaskImage/MaskImage'; import Mask from '@assets/mask.png'; const App = () => { return (
Masked content
); }; export default App; ``` #### Setting the size of the mask image container To define the size of the mask image container, use either the `style` or `class` attributes. The example below shows how to set the `width` and `height` of the container to `150px` using the `style` attribute: ```jsx import MaskImage from '@components/Media/MaskImage/MaskImage'; import Mask from '@assets/mask.png'; const App = () => { return (
Masked content
); }; export default App; ``` Since the `style` attribute is defined with an object, you can easily reuse this object across different `MaskImage` components if they need to have the same size. This pattern can also be applied to the `options` attribute, as it also accepts an object value: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/mask-image/#guide] ## MaskImage: Guide (2/6) ```jsx import { JSX } from 'solid-js'; import MaskImage from '@components/Media/MaskImage/MaskImage'; import Mask from '@assets/mask.png'; const App = () => { const maskStyle: JSX.CSSProperties = { width: '150px', height: '150px' }; return (
Masked content 1
Masked content 2
); }; export default App; ``` If the component’s styles are static and won’t change at runtime, using the `class` attribute is recommended for better performance: **App.module.css:** ```css .mask-image { width: 150px; height: 150px; } ``` ```jsx import MaskImage from '@components/Media/MaskImage/MaskImage'; import Mask from '@assets/mask.png'; import styles from './App.module.css'; const App = () => { return (
Masked content
); }; export default App; ``` #### Setting the mask image size After defining the container size, you can set the mask image size using the `options.size` property. This property accepts `'contain'`, `'cover'`, or any valid `mask-size` CSS value, such as `100px 100px` or `100%`. For more details, refer to the [mask-size documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/mask-size). The example below shows two containers with different mask sizes: one using `contain` and the other with a custom size. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/mask-image/#guide] ## MaskImage: Guide (3/6) ```jsx import { JSX } from 'solid-js'; import MaskImage from '@components/Media/MaskImage/MaskImage'; import Mask from '@assets/mask.png'; const App = () => { const maskStyle: JSX.CSSProperties = { width: '150px', height: '150px' }; return (
Masked content 1
Masked content 2
); }; export default App; ``` In the second container, the mask image will have a `width` and `height` of `100px`, making the mask smaller than the container’s `150px` dimensions. #### Repeating the mask image By default, the `MaskImage` component applies the mask image without repeating it. If the image is smaller than the container, only a single instance of the mask image will be used to mask the content. To change this behavior and repeat the mask image, you can use the `options.repeat` property with one of the following values: 1. `'x'` - Repeat on the horizontal axis. 2. `'y'` - Repeat on the vertical axis. 3. `'both'` - Repeat on both axes. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/mask-image/#guide] ## MaskImage: Guide (4/6) ```jsx import { JSX } from 'solid-js'; import { ImageOptions } from '@components/Media/shared/types'; import MaskImage from '@components/Media/MaskImage/MaskImage'; import Mask from '@assets/mask.png'; const App = () => { const maskSize: ImageOptions = { size: '100px 100px' }; const maskStyle: JSX.CSSProperties = { width: '150px', height: '150px' }; return (
Masked content 1
Masked content 2
Masked content 3
); }; export default App; ``` In this example, we reuse common options for all the `MaskImage` components by setting the `maskSize` variable. Note that it is preferred to set the type of `maskSize` to `ImageOptions` to take advantage of autocompletion for available options when using VSCode with the TypeScript plugin. #### Positioning the mask image By default, the `MaskImage` component positions the mask image starting from the top-left edge of the container. You can change this behavior using the `options.position` property, which accepts any valid mask position string. For more details, refer to the [mask-position documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/mask-position). --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/mask-image/#guide] ## MaskImage: Guide (5/6) The following example demonstrates positioning the mask using the `top`, `left`, `right`, `bottom` presets, and a custom value for the `position` option: ```jsx import { JSX } from 'solid-js'; import { ImageOptions } from '@components/Media/shared/types'; import MaskImage from '@components/Media/MaskImage/MaskImage'; import Mask from '@assets/mask.png'; const App = () => { const maskSize: ImageOptions = { size: '100px 100px' }; const maskStyle: JSX.CSSProperties = { width: '150px', height: '150px' }; return (
Masked content 1
Masked content 2
Masked content 3
); }; export default App; ``` #### Accessing the HTML element To access the HTML DOM element of the `MaskImage` component: 1. Declare a variable to hold the ref without initializing it. 2. The variable should be of type `HTMLDivElement`. 3. Set the declared variable as the value of the `ref` prop of the `MaskImage` component. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/media/mask-image/#guide] ## MaskImage: Guide (6/6) ```tsx import MaskImage from '@components/Media/MaskImage/MaskImage'; import Mask from '@assets/mask.png'; const App = () => { let ref!: HTMLDivElement; return (
Masked content
); }; export default App; ``` You can now access the HTML element of `MaskImage` using `ref` and make modifications as needed. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/performance/trackers/] ## Trackers The `Trackers` component efficiently renders multiple elements at game-world positions—such as minimap blips, nameplates, and damage numbers—that update frequently. Rather than using SolidJS signals for updates, you call `updateTrackers` directly or emit events from the game engine, and `Trackers` immediately applies the new positions to the DOM in the most performant way. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/performance/trackers/#installation] ## Trackers: Installation Every component ships with the boilerplate. If you are working in your own project, add `Trackers` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Trackers ``` The CLI pulls in whatever `Trackers` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/performance/trackers/#usage] ## Trackers: Usage Give `Trackers` an `id` - this is the channel other code will call `updateTrackers` on. Inside it, each `Trackers.Item` needs its own `id`, which is what you’ll target when moving that specific item. **index.tsx:** ```tsx import Trackers, { updateTrackers } from '@components/Performance/Trackers/Trackers'; <>
``` To test this sample click the button a few times - each click calls `updateTrackers('minimap', { id: 'blip-1', x, y })` and the blip jumps straight to the new spot. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/performance/trackers/#api] ## Trackers: API (1/2) #### Trackers Props Prop Name | Type | Default | Description `id` | `string` | \- | The identifier name that addresses this `Trackers` instance. This is the first argument you pass to `updateTrackers` method. `style` | `JSX.CSSProperties` | `{}` | Inline styles to apply directly to the component’s root element. `class` | `string` | `""` | Additional CSS classes to apply to the component. #### Trackers.Item Props Prop Name | Type | Default | Description `id` | `string` | \- | The item’s own id. This is what you target with `updateTrackers` to move, hide, or show this specific item. `style` | `JSX.CSSProperties` | `{}` | Inline styles for the item. `class` | `string` | `""` | CSS classes for the item. `scale` | `Accessor \| number` | `undefined` | Property used to control the item’s scale. Pass a signal getter or a number and the item scales whenever it changes. `rotate` | `Accessor \| number` | `undefined` | Property used to control the item’s rotation in degrees. Pass a signal getter or a number and the item rotates whenever it changes. **Note:** `scale` and `rotate` are composed into the same transform `Trackers` already uses to position the item, so they work together with position updates rather than fighting over the `transform` property. For the same reason, don’t set `transform` yourself in an item’s `style` - `Trackers` owns it, and your value would just get overwritten on the next update. #### updateTrackers --- [SOURCE: https://gameface-ui.coherent-labs.com/components/performance/trackers/#api] ## Trackers: API (2/2) This method can be used to update the position and visibility of `Trackers.Item` components within a specific `Trackers` instance directly from JavaScript. ```ts updateTrackers(trackersId: string, updates: TrackersEventPayload | TrackersEventPayload[]): void ``` Parameter | Type | Description `trackersId` | `string` | The `id` of the `Trackers` component to update. `updates` | `TrackersEventPayload \| TrackersEventPayload[]` | A single item update, or an array of them to update several items in one call. Where `TrackersEventPayload` is: Field | Type | Description `id` | `string` | The `id` of the `Trackers.Item` to update. `x` | `number` | New horizontal position, in pixels. `y` | `number` | New vertical position, in pixels. `hide` | `boolean` | Set to `true` to hide the item, `false` (or omit it) to show it. Calling `updateTrackers` for a `Trackers` id that isn’t currently mounted, or a `Trackers.Item` id that doesn’t exist, is safe - it’s simply ignored (with a warning logged in development). --- [SOURCE: https://gameface-ui.coherent-labs.com/components/performance/trackers/#trackersitem-behavior] ## Trackers: Trackers.Item behavior - Setting `class` or `style` on a `Trackers.Item`, should not overwrite the following properties otherwise it won’t be positioned correctly at runtime: - `position` - Internally `Trackers.Item` is positioned absolutely within its parent container. - `transform` - The `Trackers.Item` uses this CSS property to control its position with `translate`. If you need to scale or rotate the item use the `scale` and `rotate` props. Do not set `transform` yourself in an item’s `style` as it will be overwritten by the component. - `Trackers.Item` renders a `div` element in place, so it should be used directly as the wrapper around your item’s content. #### Good and bad practice ```tsx // ✅ Good: Trackers.Item owns the transformation, while scale and rotate are composed safely. Player // ❌ Bad: Setting transform yourself overwrites the position applied by Trackers component. ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/performance/trackers/#guide] ## Trackers: Guide (1/3) #### Move item in the UI In some cases, positions of the items are updated from the UI using JavaScript. For that reason, you may need to call `updateTrackers` every frame to reflect the changes in the UI. Make sure to call it with multiple items batched together in a single array for efficiency if you have several items to update. **index.tsx:** ```tsx import { onCleanup, onMount } from 'solid-js'; import Trackers, { updateTrackers } from '@components/Performance/Trackers/Trackers'; const App = () => { let frame: number; const tick = () => { updateTrackers('minimap', [ { id: 'blip-1', x: Math.random() * 180, y: Math.random() * 180 }, { id: 'blip-2', x: Math.random() * 180, y: Math.random() * 180 }, ]); frame = requestAnimationFrame(tick); }; onMount(() => { frame = requestAnimationFrame(tick); }); onCleanup(() => cancelAnimationFrame(frame)); return ( ); }; <> ``` #### Move item from the engine If you are using an engine and you want to control the position of a tracked item, you can emit events from the engine to the UI directly. The `Trackers` component internally listens for these events via `engine.on('trackers:', ...)` and update the items accordingly. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/performance/trackers/#guide] ## Trackers: Guide (2/3) **Note:** The event name must be `trackers:`, where `` is the `id` of the `Trackers` instance, and its argument should be a single update or an array of them - same shape as what you’d pass to `updateTrackers`. Here is an example: ```c++ struct TrackerUpdate { const char* id; float x; float y; }; class GameViewListener : public cohtml::IViewListener { public: virtual void OnDOMBuilt() override { // Safe to trigger events now that the DOM is ready and JS handlers are active. std::vector updates = { { "blip-1", 120.f, 80.f }, { "blip-2", 140.f, 92.f }, }; m_View->TriggerEvent("trackers:minimap", updates); } private: cohtml::View* m_View; }; ``` More on how to emit engine events can be found in the Gameface [documentation ](https://docs.coherent-labs.com/cpp-gameface/integration/ui_scripting/javascript_native/#c-triggering-javascript). #### Hide and show an item Set `hide: true` to hide an item, and `hide: false` (or just leave it out) to bring it back. ```tsx // Hide it updateTrackers('minimap', { id: 'blip-1', hide: true }); // Show it again updateTrackers('minimap', { id: 'blip-1', hide: false }); ``` #### Scale or rotate a tracked item `scale` and `rotate` take a signal getter, so the item reacts whenever you update the signal - no need to go through `updateTrackers` for these. **index.tsx:** --- [SOURCE: https://gameface-ui.coherent-labs.com/components/performance/trackers/#guide] ## Trackers: Guide (3/3) ```tsx import { createSignal } from 'solid-js'; import Trackers from '@components/Performance/Trackers/Trackers'; const App = () => { const [scale, setScale] = createSignal(1); const [rotate, setRotate] = createSignal(0); return ( <> ); }; <> ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/utility/navigation/] ## Navigation The `Navigation` component is a comprehensive navigation system designed for game UIs. It provides keyboard and gamepad input handling, spatial navigation between UI areas, and a flexible action system for mapping inputs to callbacks. Built on top of the [Coherent Gameface Interaction Manager](https://frontend-tools.coherent-labs.com/interaction-manager/getting-started/), it enables seamless navigation across complex menu systems and HUD elements. This component provides: - Keyboard and gamepad input management with customizable bindings - Spatial navigation with multiple navigation areas - Action system for mapping inputs to game-specific callbacks - Scope-based context awareness for different UI sections - Pause/resume functionality for navigation state - Integration with components via context and navigation actions directive --- [SOURCE: https://gameface-ui.coherent-labs.com/components/utility/navigation/#installation] ## Navigation: Installation Every component ships with the boilerplate. If you are working in your own project, add `Navigation` with the [Gameface CLI](https://frontend-tools.coherent-labs.com/gameface-cli/getting-started/): ```bash npx gameface-cli add Navigation ``` The CLI pulls in whatever `Navigation` depends on. To refresh an existing copy, update it instead. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/utility/navigation/#usage] ## Navigation: Usage To use the `Navigation` component, wrap your UI with it and define navigation areas for different sections of your UI. You can configure default actions and provide custom input bindings for your game. **Tip:** For detailed usage instructions, examples, and advanced features, refer to the Guide section. ```tsx import Navigation from '@components/Navigation/Navigation/Navigation'; import { ActionMap } from '@components/Navigation/Navigation/types'; const App = () => { const defaultActions: ActionMap = { 'tab-left': {key: {binds: ['Q'], type: ['press']}, button: {binds: ['left-shoulder'], type: 'press'}, callback: menuLeft, global: true}, 'tab-right': {key: {binds: ['E'], type: ['press']}, button: {binds: ['right-shoulder'], type: 'press'}, callback: menuRight, global: true}, 'select': {key: {binds: ['SPACEBAR'], type: ['press']}, button: {binds: ['face-button-left'], type: 'press'}}, 'back': {key: {binds: ['BACKSPACE'], type: ['press']}}, } return ( ); }; export default App; ``` --- [SOURCE: https://gameface-ui.coherent-labs.com/components/utility/navigation/#default-actions] ## Navigation: Default Actions (1/9) The Navigation component comes with a couple of pre-configured default actions that handle common navigation patterns in game UIs. These actions are automatically registered when the `Navigation` component mounts. However, components typically listen for these actions only when they are **focused**. For example, pressing Arrow Right emits a global `move-right` event, but only the currently focused `Stepper` will respond to it. This ensures that you don’t accidentally change settings in a background menu while navigating the main screen. These actions are recognized across the entire Gameface UI component library, enabling preset components to work seamlessly with the navigation system out of the box. Each default action has: - **Keyboard bindings** - One or more keyboard keys - **Gamepad bindings** - One or more gamepad buttons - **Global emission** - They emit events via the event bus, allowing any component to respond - **No default callbacks** - They don’t execute callbacks by default, only emit events. However they can be extended to execute callback as well. - **Library-wide recognition** - Preset components like Dropdown, `Stepper`, `Checkbox`, and others automatically listen to these actions #### Available Default Actions --- [SOURCE: https://gameface-ui.coherent-labs.com/components/utility/navigation/#default-actions] ## Navigation: Default Actions (2/9) Action Name | Keyboard Binding | Gamepad Binding | Purpose `move-left` | `ARROW_LEFT` | `pad-left` (D-Pad) | Directional input left (used by components Stepper) `move-right` | `ARROW_RIGHT` | `pad-right` (D-Pad) | Directional input right (used by components Stepper) `move-up` | `ARROW_UP` | `pad-up` (D-Pad) | Directional input up (used by components like Dropdown) `move-down` | `ARROW_DOWN` | `pad-down` (D-Pad) | Directional input down (used by components like Dropdown) `select` | `ENTER` | `face-button-down` | Confirm selection or activate the currently focused element `back` | `ESC` | `face-button-right` | Cancel current operation or navigate back to the previous screen `pan` | `none` | `right.joystick` | Continuous 2D input for manipulating values on two axes simultaneously. Paused by default **Reserved Action Names:** Avoid creating custom actions with names starting with `move-focus-direction` (e.g., `move-focus-left`, `move-focus-right`, etc.). These names are reserved and used internally by the spatial navigation system for managing focus between UI elements. [Read more here](https://frontend-tools.coherent-labs.com/interaction-manager/features/spatial-navigation/#actions) **Paused default action:** The `pan` action is paused by default to save performance when there are no components listening to it. If a component that is subscribed to it gets initialized, the action will automatically unpause. If you wish to subscribe to the `pan` action in your custom component, make sure to unpause it first using the `resumeAction()` method from the `useNavigation()` hook. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/utility/navigation/#default-actions] ## Navigation: Default Actions (3/9) #### Customizing Default Actions Default actions can be customized by updating their configuration. This is useful when you want to: - Change keyboard/gamepad bindings to match your game’s control scheme - Add custom callbacks to default actions - Modify input types (press, hold, lift) You can customize default actions either through the `actions` prop or programmatically using `updateAction()`: **Via props:** ```tsx import Navigation from '@components/Navigation/Navigation/Navigation'; import { ActionMap } from '@components/Navigation/Navigation/types'; const customActions: ActionMap = { // Customize the 'select' action to use SPACEBAR instead of ENTER 'select': { key: {binds: ['SPACEBAR'], type: ['press']}, button: {binds: ['face-button-down'], type: 'press'}, callback: (scope) => console.log('Selected in', scope), }, // Customize 'back' to add a callback 'back': { key: {binds: ['ESC'], type: ['press']}, button: {binds: ['face-button-right'], type: 'press'}, callback: () => handleBack(), } }; {/* Your UI */} ``` **Programmatically:** ```tsx const nav = useNavigation(); // Update the select action at runtime nav.updateAction('select', { key: {binds: ['SPACEBAR'], type: ['press']}, button: {binds: ['face-button-down'], type: 'press'}, callback: (scope) => handleSelection(scope), global: true }); ``` #### Adding Custom Actions Beyond the default actions, you can add your own custom actions for game-specific inputs: --- [SOURCE: https://gameface-ui.coherent-labs.com/components/utility/navigation/#default-actions] ## Navigation: Default Actions (4/9) ```tsx import Navigation from '@components/Navigation/Navigation/Navigation'; import { ActionMap } from '@components/Navigation/Navigation/types'; const customActions: ActionMap = { // Custom action for opening inventory 'open-inventory': { key: {binds: ['I'], type: ['press']}, button: {binds: ['face-button-top'], type: 'press'}, callback: () => openInventory(), global: true }, // Custom action for opening map 'open-map': { key: {binds: ['M'], type: ['press']}, button: {binds: ['face-button-left'], type: 'press'}, callback: (scope) => openMap(scope), global: false // Only emit locally, not globally } }; {/* Your UI */} ``` Or add them programmatically: ```tsx const nav = useNavigation(); nav.addAction('toggle-menu', { key: {binds: ['TAB'], type: ['press']}, button: {binds: ['START'], type: 'press'}, callback: () => toggleMenu(), global: true }); ``` #### Propagating Actions (anchor element) Some components may need to respond to actions when a different element is focused. You can achieve this by specifying an `anchor` element in the action configuration. When the anchor element is focused, the action will trigger for the specified element. **Tip:** The `anchor` prop can accept either a CSS selector string or a direct reference to an `HTMLElement`. In the following example, the `Stepper` component will respond to navigation actions when the parent `.menu-item` div is focused. --- [SOURCE: https://gameface-ui.coherent-labs.com/components/utility/navigation/#default-actions] ## Navigation: Default Actions (5/9) **Unique CSS Selector:** When using a CSS selector as an anchor, ensure that it uniquely identifies the desired element within the DOM to avoid unexpected behavior. The most robust method is to use an `id` selector. ```tsx