### Setup ember-primitives Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/createStore.md Installs the ember-primitives package using pnpm. This is the initial step to use the createStore utility. ```bash pnpm add ember-primitives ``` -------------------------------- ### Install ember-primitives Source: https://github.com/universal-ember/ember-primitives/blob/main/CONTRIBUTING.md Clone the repository and install dependencies using pnpm. ```bash git clone cd ember-primitives pnpm install ``` -------------------------------- ### Install ember-primitives Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/on-resize.md Installs the ember-primitives package using pnpm. This package includes the on-resize utility. ```bash pnpm add ember-primitives ``` -------------------------------- ### Install ember-primitives Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/qp.md Installs the ember-primitives package using pnpm. This is the first step to using the query parameter utilities. ```bash pnpm add ember-primitives ``` -------------------------------- ### Install `should-handle-link` Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/should-handle-link.md Installs the `should-handle-link` package using pnpm. This is a prerequisite for using the utility in your project. ```bash pnpm add should-handle-link ``` -------------------------------- ### Install ember-primitives Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/load.md Installs the ember-primitives package using pnpm. This is the first step to using the 'load' utility. ```bash pnpm add ember-primitives ``` -------------------------------- ### Install ember-primitives Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/dom-context.md This command installs the ember-primitives package using pnpm. Ensure you have pnpm installed or use your preferred package manager. ```bash pnpm add ember-primitives ``` -------------------------------- ### Ember Primitives Test Setup and Manifest Loading Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/tests/index.html This snippet demonstrates the core setup for testing in the Ember Primitives project. It imports essential testing modules, fetches a manifest file to load page data, and filters this data based on specific criteria. It also configures a global buffer object and initializes the Ember testing application. ```javascript import "ember-testing"; window.Buffer = globalThis.Buffer = { isBuffer: () => false }; let response = await fetch("/kolay-manifest/manifest.json"); let json = await response.json(); let pages = json.groups[0].list; // The accessibility page deliberately // has violations for demonstration window.__pages__ = pages.filter((page) => !page.path.includes("accessibility")); import { start } from "./test-helper"; import.meta.glob("./**/*.{js,ts,gjs,gts}", { eager: true }); await start(); ``` -------------------------------- ### Install Dependencies Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/README.md Installs the necessary project dependencies using npm. This is a standard step after cloning a project. ```bash npm install ``` -------------------------------- ### Run ember-primitives Test Application Source: https://github.com/universal-ember/ember-primitives/blob/main/CONTRIBUTING.md Start the test application to view and interact with the addon locally. ```bash cd test-app pnpm start ``` -------------------------------- ### Install Dependencies Source: https://github.com/universal-ember/ember-primitives/blob/main/test-app/README.md Installs the necessary project dependencies using npm. This is a standard step after cloning a Node.js-based project. ```bash npm install ``` -------------------------------- ### Serve Application Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/README.md Starts the Ember development server and makes the application accessible at http://localhost:4200. It also provides a link to the test runner. ```bash ember serve ``` -------------------------------- ### Install form-data-utils (Bash) Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/data-from-event.md This command installs the `form-data-utils` package using pnpm. This package provides utilities for handling form data, and it is also included with `ember-primitives` when using the `
` component. ```bash pnpm add form-data-utils ``` -------------------------------- ### Install ember-primitives Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/5-floaty-bits/anchor-to.md Installs the ember-primitives package using pnpm, which provides the anchorTo modifier and other UI primitives. ```bash pnpm add ember-primitives ``` -------------------------------- ### Install ember-primitives Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/5-floaty-bits/floating-ui.md This command installs the ember-primitives package using pnpm, which is required to use the FloatingUI component and its related functionalities. ```bash pnpm add ember-primitives ``` -------------------------------- ### Install ember-primitives Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/1-get-started/index.md This snippet shows the command to add the ember-primitives package to your project using pnpm. It's a standard installation command for Node.js projects managed with pnpm. ```bash pnpm add ember-primitives ``` -------------------------------- ### KeyCombo Usage Examples Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/3-ui/key-combo.md Illustrates various ways to use the KeyCombo component, including single keys, macOS specific shortcuts, and key combinations provided as an array. ```gjs import { Key, KeyCombo } from 'ember-primitives'; ``` -------------------------------- ### Serve Ember Application Source: https://github.com/universal-ember/ember-primitives/blob/main/test-app/README.md Starts the Ember development server, allowing you to view and interact with the application locally. The app is typically accessible at http://localhost:4200. ```bash ember serve ``` -------------------------------- ### Example Usage of Plain Anchor Links Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/4-routing/proper-links.md Provides a live preview example showcasing the use of plain `` tags for navigation after the `@properLinks` decorator has been applied. It includes links to internal routes, a hash link, and an external URL. ```gjs ``` -------------------------------- ### Basic PortalTargets Usage Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/5-floaty-bits/portal-targets.md A minimal example demonstrating the basic usage of the PortalTargets component within a template. ```gjs import { PortalTargets } from 'ember-primitives/components/portal-targets'; ``` -------------------------------- ### Header Popover Example Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/5-floaty-bits/popover.md This example demonstrates using the Popover component within a site header. It includes nested popovers, dynamic content display based on state, and custom styling for the popover elements and trigger buttons. It utilizes `ember-primitives` for the Popover and PortalTargets, `ember-resources` for state management, and `ember-focus-trap` for focus management. ```gjs import { PortalTargets, Popover } from 'ember-primitives'; import { hash } from '@ember/helper'; import { loremIpsum } from 'lorem-ipsum'; import { cell } from 'ember-resources'; import { on } from '@ember/modifier'; import { focusTrap } from 'ember-focus-trap'; const settings = cell(true); ``` -------------------------------- ### Accordion Example with Native Details Element Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/3-ui/accordion.md Demonstrates how to create an accordion-like structure using the native HTML
and elements. This example includes styling with CSS to mimic component behavior and shows how to manage multiple collapsible sections. ```gjs // No imports needed! // If you need only one open a time, use the "name" attribute // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details#name ``` -------------------------------- ### Glimmer Modal Example Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/5-floaty-bits/modal.md Demonstrates the usage of the Modal component from ember-primitives in a Glimmer application. It includes basic modal functionality, event handling for opening and closing, and styling using Open Props CSS. ```gjs import { Modal } from 'ember-primitives'; import { on } from '@ember/modifier'; import { cell } from 'ember-resources'; import { loremIpsum } from 'lorem-ipsum'; const returnValue = cell(''); ``` -------------------------------- ### Setup Proper Links in Ember Router Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/4-routing/proper-links.md Demonstrates how to import and apply the `@properLinks` decorator to the Ember Router class in `app/router.js` to enable plain `` tag navigation. ```javascript // app/router.js import EmberRouter from "@ember/routing/router"; import config from "docs-app/config/environment"; + import { properLinks } from "ember-primitives/proper-links"; + @properLinks export default class Router extends EmberRouter { location = config.locationType; rootURL = config.rootURL; } ``` -------------------------------- ### Importing VisuallyHidden Component (JS) Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/visually-hidden.md Provides examples of importing the VisuallyHidden component from the 'ember-primitives' library in JavaScript (JS). It covers both standard import and a specific import for non-tree-shaking environments. ```js import { VisuallyHidden } from 'ember-primitives'; ``` ```js import { VisuallyHidden } from 'ember-primitives/components/dialog'; ``` -------------------------------- ### OTPInput Basic Usage Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/3-ui/one-time-password/otp-input.md A simple example of how to use the OTPInput component within a template, including a label for accessibility. This demonstrates the basic rendering of the input field. ```gjs import { OTPInput } from 'ember-primitives'; ``` -------------------------------- ### Zoetrope Component Basic Usage Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/3-ui/zoetrope.md A fundamental example of using the Zoetrope component with a header and content sections. It demonstrates the basic structure and props like `@gap` and `@offset`. ```gjs import { Zoetrope } from "ember-primitives"; ``` -------------------------------- ### Glimmer DSL for JavaScript Popover Example Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/5-floaty-bits/popover.md This snippet demonstrates the usage of the Popover component from ember-primitives. It utilizes Glimmer DSL for JavaScript (gjs) and includes a template with a Popover, a reference element ('the hook'), and the popover content. It also incorporates PortalTargets for managing portal layering and includes inline styles for the popover's appearance and behavior. ```gjs import { PortalTargets, Popover } from 'ember-primitives'; import { array, hash } from '@ember/helper'; import { loremIpsum } from 'lorem-ipsum'; ``` -------------------------------- ### Build ember-primitives Addon Source: https://github.com/universal-ember/ember-primitives/blob/main/CONTRIBUTING.md Build the ember-primitives addon for distribution or local use. ```bash cd ember-primitives pnpm build ``` -------------------------------- ### Run ember-primitives Tests Source: https://github.com/universal-ember/ember-primitives/blob/main/CONTRIBUTING.md Execute the test suite for the ember-primitives project, either once or in watch mode. ```bash cd test-app pnpm test pnpm test:watch ``` -------------------------------- ### Switch Component Example (GJS) Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/2-accessibility/index.md Illustrates the use of the Switch component in Glimmer.js (GJS). This example shows a Switch component rendered without an associated label, which is a common accessibility issue that ember-primitives highlights during development. ```gjs import { Switch } from 'ember-primitives'; ``` -------------------------------- ### Nested Portals Example Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/5-floaty-bits/portal.md Demonstrates nesting of Portal components to create layered content, such as tooltips or popovers within other popovers. This example showcases how Portals can be targeted to specific DOM elements, creating a hierarchical structure for UI elements. ```gjs import { Portal } from 'ember-primitives/components/portal'; ``` -------------------------------- ### Build Ember Application Source: https://github.com/universal-ember/ember-primitives/blob/main/test-app/README.md Compiles the Ember application for deployment. The `--environment production` flag optimizes the build for production use. ```bash ember build ``` ```bash ember build --environment production ``` -------------------------------- ### Import Key and KeyCombo Components Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/3-ui/key-combo.md Shows different ways to import the Key and KeyCombo components from the ember-primitives library, including a path for non-tree-shaking environments. ```js import { Key, KeyCombo } from 'ember-primitives'; ``` ```js import { Key, KeyCombo } from 'ember-primitives/components/keys'; ``` -------------------------------- ### Shadowed Component Example: Style Isolation Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/shadowed.md This example showcases the core functionality of the Shadowed component. It renders a paragraph element directly, which is affected by global styles, and then renders another paragraph within the Shadowed component, demonstrating its isolation from those same global styles. ```gjs import { Shadowed } from 'ember-primitives'; ``` -------------------------------- ### Build Application Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/README.md Compiles the Ember application for deployment. The `--environment production` flag optimizes the build for production. ```bash ember build ``` ```bash ember build --environment production ``` -------------------------------- ### Dark/Light Theme Switch Example Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/3-ui/switch.md Implements a dark/light theme toggle using the Ember Primitives Switch component. This example includes custom CSS for styling the switch and toggling a 'dark' class on the parent element to change the theme. It also incorporates SVG icons for sun and moon. ```gjs import { Switch } from 'ember-primitives'; import { on } from '@ember/modifier'; const toggleTheme = (e) => e.target.closest('div').classList.toggle("dark"); // 🎵 It's raining, it's pouring, ... 🎵 // https://www.youtube.com/watch?v=ll5ykbAumD4 const Sun = ; const Moon = ; ``` -------------------------------- ### Render Key and KeyCombo Components Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/3-ui/key-combo.md Demonstrates the usage of Key and KeyCombo components for displaying single keys and key combinations. Includes styling for the element. ```gjs import { Key, KeyCombo } from 'ember-primitives'; ``` -------------------------------- ### Lint ember-primitives Source: https://github.com/universal-ember/ember-primitives/blob/main/CONTRIBUTING.md Run linting checks to ensure code quality and style consistency. ```bash pnpm lint pnpm lint:fix ``` -------------------------------- ### Utility for Application Singleton Store Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/createStore.md Provides a helper utility function to simplify the creation of application-wide singleton stores. This wraps the createStore call with getOwner. ```js import { createStore } from 'ember-primitives/store'; import { getOwner } from '@ember/owner'; class MyState {} function createState(context) { let owner = getOwner(this); return createStore(owner, MyState); } class Demo extends Component { // lazyily created upon access of `foo`. // will be the same instance everywhere in the application get foo() { return createState(this); } } ``` -------------------------------- ### Basic Toggle Usage Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/3-ui/toggle.md A simple example of how to render the Toggle component with basic accessibility attributes. ```gjs import { Toggle } from 'ember-primitives'; ``` -------------------------------- ### Add ember-focus-trap Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/5-floaty-bits/modal.md This command installs the `ember-focus-trap` addon, which is used to manage focus within modals according to ARIA guidelines. ```bash pnpm add ember-focus-trap ``` -------------------------------- ### Ember Code Generation Source: https://github.com/universal-ember/ember-primitives/blob/main/test-app/README.md Demonstrates how to use Ember CLI's code generation capabilities. Running `ember help generate` provides a list of available generators. ```bash ember help generate ``` -------------------------------- ### Create Application Singleton Store Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/createStore.md Shows how to create a store instance that is shared across the entire application. This is achieved by passing the application owner obtained via getOwner. ```js import { createStore } from 'ember-primitives/store'; import { getOwner } from '@ember/owner'; class MyState {} class Demo extends Component { // lazyily created upon access of `foo`. // will be the same instance everywhere in the application // get foo() { return createStore(getOwner(this), MyState); } } ``` -------------------------------- ### Create Store with Arguments Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/createStore.md Illustrates creating a store instance with arguments passed to the state's constructor. The createStore utility accepts a factory function for this purpose. ```js import { createStore } from 'ember-primitives/store'; class MyState { constructor(/* .. */) { /* ... */ } } class Demo extends Component { // or get foo() { return createStore(this, () => new MyState(1, 2)); } } ``` -------------------------------- ### Initialize Tabster Keyboard Support (TypeScript) Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/2-accessibility/index.md Shows how to initialize tabster for keyboard support within an Ember application's route using TypeScript. It includes importing the setupTabster function and calling it in the `beforeModel` hook, passing `this` for proper cleanup. ```typescript import Route from '@ember/routing/route'; import { service } from '@ember/service'; import{ setupTabster } from 'ember-primitives/tabster'; export default class Application extends Route { async beforeModel() { // the 'this' is passed so that tabster is cleaned up // when the route (or in this case: application) // is destroyed or unmounted await setupTabster(this); } } ``` -------------------------------- ### Create Store with Service and Cleanup Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/createStore.md Demonstrates integrating services and managing cleanup for a store instance. Services can be accessed, and registerDestructor can be used for cleanup logic when the component is torn down. ```js import { createStore } from 'ember-primitives/store'; import { service } from '@ember/service'; class MyState { @service router; constructor(/* .. */) { registerDestructor(this, () => { // cleanup runs when Demo is torn down }); } } class Demo extends Component { // or get foo() { return createStore(this, () => new MyState(/* ... */)); } } ``` -------------------------------- ### Zoetrope with Custom Styled Controls Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/3-ui/zoetrope.md Shows how to implement custom controls for the Zoetrope component with custom styling and placement. The example includes CSS to position the controls absolutely and style the buttons. ```gjs import { Zoetrope } from "ember-primitives"; import { on } from "@ember/modifier"; ``` -------------------------------- ### Bold Text Toggle Example Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/3-ui/toggle.md Demonstrates how to use the Toggle component to create a bold text toggle button. Includes custom styling for visual feedback when the toggle is active. ```gjs import { Toggle } from 'ember-primitives'; ``` -------------------------------- ### Link with State Attributes Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/4-routing/link.md Illustrates how to use the Link component and style it based on its active state using the `data-active` attribute. This example shows styling for the current page and a related page. ```gjs import { Link } from 'ember-primitives'; ``` -------------------------------- ### Create Store in Component (Eager) Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/6-utils/createStore.md Shows how to eagerly create a store instance for a component. The store is initialized when the component instance is created. ```js import { createStore } from 'ember-primitives/store'; class MyState {} class Demo extends Component { // or eagrly created when `Demo` is created foo = createStore(this, MyState); } ``` -------------------------------- ### Switch Component with Styling (Glimmer) Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/3-ui/switch.md Provides an example of using the Switch component with custom CSS styling in Glimmer. It demonstrates how to apply styles based on the component's state using the :has selector. ```gjs import { Switch } from 'ember-primitives'; ``` -------------------------------- ### Sticky Footer with Revealing Extra Footer Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/8-layout/sticky-footer.md Implements a sticky footer that appears above a site-wide footer. As the user scrolls, more information in the sticky footer is revealed. This example showcases positioning and overflow handling for layered footers. ```gjs import { StickyFooter } from 'ember-primitives'; import { on } from '@ember/modifier'; import { TrackedArray } from 'tracked-built-ins'; import { loremIpsum } from 'lorem-ipsum'; const content = new TrackedArray(); const addContent = () => content.push(loremIpsum({ count: 1, units: 'paragraph' })); const removeContent = () => content.splice(-1); ``` -------------------------------- ### Importing Modal and Dialog Components Source: https://github.com/universal-ember/ember-primitives/blob/main/docs-app/public/docs/5-floaty-bits/modal.md Shows how to import the Modal and Dialog components from the 'ember-primitives' library. It provides two import methods: a standard import and an import for non-tree-shaking environments. ```js import { Modal, Dialog /* alias */ } from 'ember-primitives'; ``` ```js import { Modal, Dialog /* alias */ } from 'ember-primitives/components/dialog'; ```