--- url: /reference/items/Frame/examples.md --- # Examples ## Simple Intercepting clicks on links, displaying a loader and updating the targets' content. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Frame } from '@studiometa/ui'; registerComponent(Frame); ``` ::: ## Target modes: replace, append, prepend In the following example, we implement three different `FrameTarget` components, each with one the available content update strategy ("mode"): replace (the default), append or prepend. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Frame } from '@studiometa/ui'; registerComponent(Frame); ``` ::: ## Form :::code-group ```js import { Base, createApp } from '@studiometa/js-toolkit'; import { Frame, DataComputed, DataModel, Action } from '@studiometa/ui'; class App extends Base { static config = { name: 'App', refs: ['form'], components: { Frame, DataModel, DataComputed, Action, } }; mounted() { this.$refs.form.requestSubmit(); } } export default createApp(App); ``` ::: ## Adding a product to a cart This example uses the [`Frame` components](/reference/items/Frame/), as well as the [`Action`](/reference/items/Action/), [`Figure`](/reference/items/Figure/) and [`Dialog`](/reference/items/Dialog/) components, to add support for adding products to a cart without reloading the page. The `FrameForm` and `FrameAnchor` components are used to intercept click on links and form submission to make request in the background. The `FrameLoader` component displays a nice loader while the request are made. The `FrameTarget` components are then used to update some of the content on the page. The `Dialog` component is used to display a nice cart as a drawer (see [Building a drawer](/reference/items/Dialog/#building-a-drawer)) and the `Action` component listens to the `Frame` event `frame-content`, which signals that the new content is being inserted, to open the cart and display the newly inserted content. :::code-group ```css html.dark { background-color: #222; color: #eee; } body { padding: 1rem; } .z-above { z-index: 1; } .z-under { z-index: -1; } ``` :::