# Components The framework ships a library of reusable Vue components under `src/resources/src/components/`. ## Component list | Component | Description | | --------------------- | ------------------------------------------------------------------------------ | | `Button` | Styled button with label/icon/slot | | `Input` | Text input with label, formatting categories, maxlength counter, error display | | `InputPasswordToggle` | Password input with show/hide toggle | | `InputGroup` | Two-part input (editable + readonly) | | `Select` | Searchable select with infinite-scroll, pagination, and API fetching | | `TextArea` | Textarea with floating label & maxlength counter | | `Checkbox` | Checkbox with v-model | | `Switch` | Toggle switch | | `Modal` | Bootstrap modal via teleport into `#modal-show` | | `Toast` | Bootstrap toast via teleport | | `Spinner` | Loading spinner | | `Datepicker` | Date/datetime/month/year picker | | `DataTable` | Full data table with search, pagination, bulk delete, and skeleton loading | | `DataTableSkeleton` | Skeleton placeholder shown while data loads | | `Pagebar` | Teleports title into the header's page title area | | `Refresh` | Binds a click handler to the header's refresh button | | `Href` | Styled anchor link | | `FloatButton` | Positioned fixed action button | | `FeatureButton` | Header action button (injected via `featureButtons`) | --- ## DataTable A fully-featured data table with server-side pagination, search, bulk delete, and configurable page size. Works with any paginated API response via the `PaginatedData` interface. **Import:** ```vue ``` ### Props | Prop | Type | Default | Description | | ------------ | ---------------------- | -------- | -------------------------------------------------------------------------------------- | | `data` | `PaginatedData` | required | Server response — must have `{ data, current_page, last_page, per_page, total, path }` | | `search` | `string` | `""` | Initial search query (typically from `route.query.search`) | | `loop` | `DataRow[] \| false` | — | Override rows (useful for local data). Falls back to `data.data` | | `option` | `(string \| number)[]` | `[]` | Per-page size options for the "Show X entries" dropdown | | `removable` | `boolean` | `true` | Show checkboxes and trash button for bulk delete | | `countable` | `boolean` | `true` | Show row number column | | `searchable` | `boolean` | `true` | Show search input in header | | `optionable` | `boolean` | `true` | Show "Show X entries" dropdown | | `disabled` | `boolean` | `false` | Disable all interactive elements | | `filters` | `Record` | `{}` | Extra query params merged into every navigation (win over `page`/`size`/`search`) | | `fetcher` | `(params) => Promise` | — | Store-owned fetch. When set, the controls call it and keep the URL in sync | ### Slots | Slot | Bindings | Description | | ------------- | ----------------- | -------------------------------------------------------------------- | | `extra-tools` | — | Additional buttons/controls in the card header (right side) | | `extra` | — | Content inserted before the table (inside card body) | | `customhead` | — | Replace the entire `` (hides default thead) | | `thead` | — | Extra `` columns appended after checkbox + `#` columns | | `custombody` | — | Replace the entire `` (hides default tbody) | | `tbody` | `{ td: DataRow }` | Per-row `` columns. Use `` in parent | ### Events | Event | Payload | Description | | -------- | ---------------------- | --------------------------------------------------------------- | | `remove` | `(string \| number)[]` | Emitted when the trash button is clicked, with selected row IDs | ### `PaginatedData` interface ```ts interface PaginatedData { data: DataRow[]; current_page: number; last_page: number; per_page: number; total: number; path: string; } ``` ### Usage with server-side pagination The standard pattern: fetch data in a store via `useGum().get()`, pass the paginated response to DataTable, and handle search/page/size changes via the store. ```vue ``` ### Real-world example — simple CRUD table A compact table showing user info with edit/delete actions, inline status toggle, and view modal: ```vue ``` ### Multi-column table Multiple columns with nested object access: ```vue ``` ### Filters and fetcher mode The built-in search, page-size and pagination controls **preserve the current URL query** — they only override `page`, `size` and `search`. So filters that live in the URL (`?divisionId=3`) survive a search, a page-size change, or a page click. **Filters in the URL** need no prop — put them in the query and read them back in your watcher: ```ts watch( () => route.query, () => store.fetchPosts({ page: Number(route.query.page || 1), size: Number(route.query.size || 10), search: String(route.query.search || ""), divisionId: route.query.divisionId, }), { immediate: true }, ); ``` **Filters passed as a prop** (kept out of the URL) go through `:filters` and are merged last, so they always win: ```vue ``` **Fetcher mode (preferred).** When the page has a store action, hand it to the table — `:fetcher="store.index"`. The controls call the store directly and keep the URL in sync, so links stay shareable and back/forward still work, and the table owns its own search / page-size / pagination fetches: ```vue ``` > Do **not** combine `:fetcher` with `watch(route.query)` — both fetch, so every click fires two requests. With `:fetcher`, drop the watcher and load the first page once (`onMounted`). See [Gum](/guide/resources/gum). **URL mode** is the fallback when the page has no store action: the controls only rewrite the URL and your `watch(() => route.query, ...)` does the fetching. ### Key points - **Pass all three: `data`, `search` and `option`.** `data` must be the paginator's object (`{ data, current_page, last_page, per_page, total, path }`), never a bare array — the component reads `data.path`, `data.current_page` and `data.per_page`. `option` is the page-size list (`:option="[10, 25, 50]"`); the active size is resolved by matching `data.per_page` against it. - **Search, page size and pagination preserve the URL query.** **Prefer fetcher mode** whenever the page has a store action: `:fetcher="store.index"` makes the table call the store itself (through `gum.getWith`) and still updates the URL — give the page a single `onMounted` load and drop `watch(route.query)`, or each navigation fetches twice. URL mode is the fallback when there is no store action: the controls call `gum.get(..., { skipFetch: true })` to rewrite `?page=&size=&search=` while keeping every other param, and your page's `watch(() => route.query, ...)` performs the fetch. Pass `:search="String(route.query.search || '')"` so the term is seeded and paging keeps it. - **The scroll position is kept on a page click.** Both modes pass `preserveScroll: true`, and the table re-applies the saved position until the document settles — so swapping the rows for a shorter loading skeleton no longer drops you at the top. The router cooperates by not scrolling on a same-path query change. - **No sort functionality.** DataTable does not sort rows client-side. If you need sorted data, sort it server-side before passing to the `data` prop. - **Use `DataTableSkeleton` while loading** — show it when your data is null/empty, then swap to `DataTable` once data arrives. - **`removable` controls checkboxes.** When `false`, no checkboxes or trash button appear. The parent can also conditionally pass `:removable="hasRole('admin')"` to restrict bulk delete to certain roles. --- ## Datepicker A date/time picker wrapping `@vuepic/vue-datepicker`. Supports `date`, `datetime`, `month`, and `year` modes with locale-friendly input formats. Falls back to a native `` for month mode on Firefox. **Import:** ```vue ``` ### Props | Prop | Type | Default | Description | | ------ | ------------------------------------------- | -------- | ------------------------------------- | | `mode` | `"date" \| "datetime" \| "month" \| "year"` | `"date"` | Picker mode | | `err` | `string \| boolean` | `false` | Error message shown below the picker | | `must` | `boolean` | — | Show the required indicator dot | | `hood` | `string \| boolean` | — | Right-aligned caption above the input | All additional `@vuepic/vue-datepicker` props (like `model-type`, `placeholder`, `disabled`, `readonly`) are passed through via `v-bind="$attrs"`. See the [vue-datepicker docs](https://vuepic.github.io/vue-datepicker/) for the full list. **Inherited via `$attrs`:** | Attr | Type | Description | | ------------- | --------- | -------------------------------------------------------- | | `label` | `string` | Label text shown above the picker | | `parentclass` | `string` | CSS class on the wrapper div (default `"mb-2"`) | | `model-type` | `string` | Format of the emitted value (e.g. `"yyyy-MM"` for month) | | `placeholder` | `string` | Placeholder text in the input | | `disabled` | `boolean` | Disable the picker | | `readonly` | `boolean` | Make the picker read-only | ### Input formats | Mode | Input display format | Emits | | ---------- | -------------------------- | ------------------------------------------ | | `date` | `dd/MM/yyyy` | `Date` | | `datetime` | `dd/MM/yyyy hh:mm a` (12h) | `Date` | | `month` | `MM/yyyy` | `string \| Date` (depends on `model-type`) | | `year` | `yyyy` | `string \| Date` (depends on `model-type`) | ### Usage ```vue ``` ### Real-world example — month picker with `model-type` Common pattern: month picker that emits a `"yyyy-MM"` string for API submission. ```vue ``` ### Real-world example — range pickers (start/end) Two independent Datepickers for a date range filter. The `parentclass` attr controls spacing: ```vue ``` ### Real-world example — disabled on edit When editing an existing record, the Datepicker is disabled: ```vue ``` ### Key points - **Always set `model-type`** when using month/year mode to control the emitted string format (e.g. `"yyyy-MM"`). - **Month mode on Firefox** falls back to a native `` automatically — no configuration needed. - **`mode="datetime"` uses 12-hour format** (`hh:mm a`) by default. The `time-config` prop is set internally to `{ is24: false }`. - **Use `parentclass`** to control spacing or add dynamic error styling (e.g. `border border-danger rounded-2`). - **Pass `placeholder`** as a regular attr — it shows inside the input field. - **Use `disabled`** to lock the picker in edit mode (common pattern: `:disabled="Boolean(form.data.id)"`). --- ## Select A searchable select with infinite-scroll pagination and API data fetching. Built on `vue-select`. Handles everything from simple static option lists to server-side paginated searches with dependent (cascade) dropdowns. **Import:** ```vue ``` ### Props | Prop | Type | Default | Description | | -------------- | ------------------------ | ------- | ------------------------------------------------------------------------------------------------------ | | `fetched` | `(payload) => FetchPack` | — | Function returning `{ url, data, mapFn, params?, option? }`. Called internally for search/reset/reload | | `must` | `boolean` | — | Show a required-field indicator (red dot next to label) | | `err` | `string \| boolean` | — | Validation error text displayed below the select | | `hood` | `string \| boolean` | — | Right-aligned hint/helper text next to the label | | `defaultValue` | `SelectValue` | `null` | Pre-select a value on mount | | `resetKey` | `any` | `null` | **Cascade key.** When this changes, the select clears + reloads automatically | **Inherited via `v-bind="$attrs"`:** | Attr | Type | Description | | ------------- | --------- | ---------------------------------------------------------- | | `title` | `string` | Label text | | `label` | `string` | Key to use as display label in options (default `"title"`) | | `placeholder` | `string` | Placeholder text in the search input | | `id` | `string` | Sets `for` on the label | | `parentclass` | `string` | CSS class on the wrapper div (default `"mb-2"`) | | `multiple` | `boolean` | Enable multi-select | | `options` | `array` | Static options array (for non-API mode) | | `disabled` | `boolean` | Disable the select | ### Events | Event | Payload | Description | | --------- | ------- | ---------------------------------------------------------- | | `fetched` | — | Emitted after options are fetched | | `clear` | — | Emitted when the selection is cleared (via × or backspace) | ### Exposed methods | Method | Description | | ---------- | --------------------------------------- | | `reload()` | Reset selection and re-fetch first page | ### `FetchPack` interface ```ts interface FetchPack { url: string; // API endpoint data: string; // key in response that holds the paginated data params?: Record; // extra query params (e.g. filter by parent) mapFn?: (item) => Record; // transform API row → { id, title, ... } option?: (value) => void; // callback fired when selection changes } ``` The component adds `page`, `size`, and `search` params automatically. Your `mapFn` receives the raw API row — transform it to the shape your app needs (usually `{ id, title }`). ### Basic usage — API-fetched The standard pattern: `fetched` is a function returning the fetch config. The component handles search, page changes, and infinite scroll internally. ```vue ``` ### Real-world example — simple Select with store function When the fetch function lives in a store and requires form-scoped data, wrap it in an arrow: ```vue ``` **Store (for reference):** ```ts // stores/role.ts export const useRoleStore = defineStore("role", () => { const roleDD = () => ({ url: "/api/role/dropdown", data: "data", mapFn: (item: any) => ({ id: Number(item.id), title: String(item.name || ""), }), }); return { roleDD }; }); ``` ### Dependent (cascade) dropdown with `resetKey` When a parent select changes, the child automatically reloads via `resetKey`. The child's `fetched` function reads the parent's value for its `params`. ```vue ``` When `form.data.commissionerate` changes → `resetKey` on the division Select changes → select clears + reloads → `fetched` runs again, picks up the new `commissionerateId` in params. ### Multi-level cascade (3+ levels) For three or more levels, chain `resetKey` at each level: ```vue ``` ### `option` callback for side effects Use `option` in the returned `FetchPack` to react when selection changes — e.g., clearing dependent dropdowns, reloading child data, or fetching related records. Single callback: ```ts const fetchUser = () => ({ url: "/api/auth/user/dropdown/revenue", data: "data", mapFn: (item: any) => ({ id: Number(item.id), title: String(item.email || item.name || ""), }), option: (selected: any) => { // selected is the chosen option object, or null on clear entitySelect.value?.reload(); // clear + reload dependent Select via ref }, }); ``` Multiple callbacks (array): ```ts const fetchUser = () => ({ url: "/api/auth/user/dropdown", data: "data", mapFn: (item: any) => ({ id: item.id, title: item.name }), option: [ (val: any) => { form.user = val; }, (val: any) => { form.entity = null; entitySelect.value?.reload(); }, ], }); ``` ### Edit mode — populating cascading dropdowns When editing a record with cascade-dependent selects, you **must** `await nextTick()` between each cascade level in `setForm`. This gives the child Select's `resetKey` watch time to fire, clear the old value, and reload options before you set the next level. ```vue ``` **Why `nextTick` is required:** When you set `form.data.commissionerate`, the division Select's `resetKey` changes, triggering its internal watch. That watch clears the division model (setting it to `null`) and fetches fresh options. Without `nextTick`, setting `form.data.division` immediately after would be overwritten by the watch. `nextTick` lets the flush complete so the child resets first, then you can safely set its value. **Do NOT use `nextTick` for user cascade.** The `resetKey` watch handles that automatically — user changes a parent → watch fires → child clears + reloads. `nextTick` is only needed in `setForm` when programmatically restoring all cascade levels at once. ### Reloading from outside via `ref` You can call `reload()` on a Select from outside using a template ref — useful after an external event (e.g. Pulse broadcast) indicates the dropdown data has changed: ```vue ``` ### Static options (no API) For simple cases where options don't come from an API: ```vue ``` ### Search behavior When you type in the search box, results are fetched from the API. If you clear the search, the select refetches the full list and **pins the results of your last search on top** so you don't lose your place. Selecting an option clears this pinned state. ### Key points - **`fetched` is a plain function** — not reactive, not a computed. It runs fresh on every search/page/reload. Your function closes over reactive form values, so it always reads the latest parent state. - **`label="title"`** is the default display key — options should have an `id` and `title` field (or whatever you set `label` to). - **`resetKey` must be a primitive or reactive ref** — when it changes, the component clears and reloads. Pass the parent's `id` (e.g. `form.data.country?.id`). - **Use `reload()` via ref** when external data changes (e.g. after a Pulse broadcast or form submission that affects the dropdown). - **Infinite scroll** is built in — when the user scrolls to the bottom of the dropdown, the next page loads automatically. - **`option` can be a function or array of functions** — each is called with the selected value (or `null` on clear) when the selection changes. --- ## FeatureButton `FeatureButton` adds an action button into the app header. It registers itself with the layout's `featureButtons` provider on mount and removes itself on unmount, so header buttons are automatically scoped to the page that renders them. ```vue ``` ### Props | Prop | Type | Description | | ------------- | -------- | ------------------------------------------- | | `icon` | `string` | Bootstrap icon class (e.g. `bi bi-plus-lg`) | | `label` | `string` | Text shown next to the icon | | `title` | `string` | Tooltip (falls back to `label`) | | `buttonClass` | `string` | CSS class applied to the header button | ### Slots | Slot | Description | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `default` | Custom content. When present, the button is replaced by a slot renderer (wrapped with the same order/class as a normal button) — useful for dropdowns or compound controls. | ### Usage with role-based visibility ```vue ```