Install SwiftWC with Ember.js
How to install dependencies and structure your Ember.js app.
Create your project
bash
npx ember-cli new my-project --embroider --no-welcome
cd my-projectInstall SwiftWC
bash
ember install @swiftwc/ui@latestbash
npm i -D @swiftwc/ui@latestbash
bun add --exact @swiftwc/ui@latest --devImport the CSS file
app.ts
ts
import Application from '@ember/application';
import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from 'my-project/config/environment';
import '@swiftwc/ui/styles.css';
import '@swiftwc/ui/client';
export default class App extends Application {
modulePrefix = config.modulePrefix;
podModulePrefix = config.podModulePrefix;
Resolver = Resolver;
}
loadInitializers(App, config.modulePrefix);Prioritize CSS layers
Add all sw-* layers after other base rules. For example, Tailwind CSS applies global margin, padding, and border resets accross the page using a base @layer.
To properly install SwiftWC, add a @layer rule at the begining of your stylesheet and move all other base layers at the begining, then follow with all the SwiftWC layers, and finally add any other layers you need, for example Tailwind requires 3 more layers.
Your styles file should look like this:
app.css
ts
/* Ember supports plain CSS out of the box. More info: https://cli.emberjs.com/release/advanced-use/stylesheets/ */
@import 'tailwindcss';
@layer base, sw-base, sw-components, sw-nav-components, sw-tab-components, sw-utils, sw-colors, sw-ui, sw-transitions, sw-final, components, utilities, theme;Start your build process
bash
npm startStart using SwiftWC web components in your project
glimmer-ts
import { pageTitle } from 'ember-page-title';
<template>
{{pageTitle "MyProject"}}
<v-keyboard></v-keyboard>
{{outlet}}
</template>ts
import EmberRouter from "@embroider/router";
import config from "my-project/config/environment";
export default class Router extends EmberRouter {
location = config.locationType;
rootURL = config.rootURL;
}
Router.map(function () {
this.route("about");
});gts
import { pageTitle } from 'ember-page-title';
import { startViewTransition } '@swiftwc/ui/client';
const handleClick = async (event) => {
await startViewTransition(event.target, 'forwards', async () => {
this.router.transitionTo('about');
});
}
<template>
<navigation-stack>
<scroll-view>
<v-stack>
<button is="borderless-button" type="button" {{on "click" handleClick}}>About</button>
</v-stack>
</scroll-view>
{{outlet}}
</navigation-stack>
</template>glimmer-ts
import { pageTitle } from 'ember-page-title';
import { startViewTransition } '@swiftwc/ui/client';
const handleClick = async (event) => {
await startViewTransition(event.target, 'backwards', async () => {
this.router.transitionTo('index');
});
}
<template>
<body-view>
<scroll-view>
<v-stack>
<button is="borderless-button" type="button" {{on "click" handleClick}}>Back</button>
</v-stack>
</scroll-view>
{{outlet}}
</body-view>
</template>