Home
Softono
A

Adobe

Professional software vendor delivering innovative solutions on the Softono platform. Specialized in both open-source and proprietary software development.

Total Products
4

Software by Adobe

react-spectrum
Open Source

react-spectrum

# [React Spectrum Libraries](https://react-spectrum.adobe.com/) A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences. ### React Spectrum A React implementation of Spectrum, Adobe’s design system. Spectrum provides adaptive, accessible, and cohesive experiences for all Adobe applications. [Explore React Spectrum](https://react-spectrum.adobe.com/react-spectrum/index.html) ### React Aria A library of unstyled React components and hooks that helps you build accessible, high quality UI components for your application or design system. [Learn more about React Aria](https://react-spectrum.adobe.com/react-aria/index.html) ### React Stately A library of React Hooks that provides cross-platform state management for your design system. [More information about React Stately](https://react-spectrum.adobe.com/react-stately/index.html) ### Internationalized A collection of framework-agnostic internationalization libraries for the web. [Internationalized Packages](https://react-spectrum.adobe.com/internationalized/index.html) ## Features * ♿️ **[Accessible](https://react-spectrum.adobe.com/react-aria/accessibility.html)** – Accessibility and behavior is implemented according to [WAI-ARIA Authoring Practices](https://www.w3.org/TR/wai-aria-practices-1.2/), including full screen reader and keyboard navigation support. All components have been tested across a wide variety of screen readers and devices to ensure the best experience possible for all users. * 📱 **[Adaptive](https://react-spectrum.adobe.com/react-aria/interactions.html)** – All components are designed to work with mouse, touch, and keyboard interactions. They’re built with responsive design principles to deliver a great experience, no matter the device. * 🌍 **[International](https://react-spectrum.adobe.com/react-aria/internationalization.html)** – Support over 30 languages is included out of the box, including support for right-to-left languages, date and number formatting, and more. * 🎨 **[Customizable](https://react-spectrum.adobe.com/react-spectrum/theming.html)** – React Spectrum components support custom themes, and automatically adapt for dark mode. For even more customizability, you can build your own components with your own DOM structure and styling using the [React Aria](https://react-spectrum.adobe.com/react-aria/index.html) and [React Stately](https://react-spectrum.adobe.com/react-stately/index.html) hooks to provide behavior, accessibility, and interactions. ## Getting started React Spectrum includes several libraries, which you can choose depending on your usecase. * [React Spectrum](https://react-spectrum.adobe.com/react-spectrum/getting-started.html) is an implementation of Adobe's design system. If you’re integrating with Adobe software or would like a complete component library to use in your project, look no further! * [React Aria](https://react-spectrum.adobe.com/react-aria/getting-started.html) is a collection of unstyled React components and hooks that helps you build accessible, high quality UI components for your own application or design system. If you're building a component library for the web from scratch with your own styling, start here. * [React Stately](https://react-spectrum.adobe.com/react-stately/getting-started.html) is a library of state management hooks for use in your component library. If you're using React Aria, you'll likely also use React Stately, but it can also be used independently (e.g. on other platforms like React Native). [Read more about our architecture](https://github.com/adobe/react-spectrum/blob/main/rfcs/2019-v3-architecture.md). ## Contributing One of the goals of the React Spectrum project is to make building design systems and component libraries as easy as possible, while maintaining high quality interactions and accessibility support. We aim to raise the bar for web applications. The best way to achieve that goal is **together**. We would love contributions from the community no matter how big or small. 😍 Read our [contributing guide](https://github.com/adobe/react-spectrum/blob/main/CONTRIBUTING.md) to learn about how to propose bugfixes and improvements, and how the development process works. For detailed information about our architecture, and how all of the pieces fit together, read our [architecture rfc](https://github.com/adobe/react-spectrum/blob/main/rfcs/2019-v3-architecture.md).

CSS Frameworks & UI Kits JavaScript Libraries & Components
15.3K Github Stars
spectrum-css
Open Source

spectrum-css

<div align="right"> ![GitHub Actions build status on main](https://img.shields.io/github/actions/workflow/status/adobe/spectrum-css/production.yml?branch=main&style=for-the-badge&label=main) <br/> ![GitHub Actions build status on spectrum-two](https://img.shields.io/github/actions/workflow/status/adobe/spectrum-css/production.yml?branch=spectrum-two&style=for-the-badge&label=spectrum-two) </div> <h1 align="center">Spectrum CSS</h1> <h3 align="center">A CSS-implementation of the Spectrum design language</h3> <img src=".storybook/assets/images/spectrum-css_illustration_desktop.png"> ## Features - 📖 **Robust documentation**: Spectrum CSS is designed to be used in partnership with [Spectrum's detailed usage guidelines](https://spectrum.adobe.com/). - 🎨 **Flexible**: Our CSS is customizable, powerful, and designed to work with any JavaScript framework. - 🧪 **Rigorously tested**: These individually-versioned components have been vetted to be accessible and inclusive of global audiences. - 📱 **Multi-platform support**: We support [evergreen browsers](https://github.com/adobe/spectrum-css?tab=readme-ov-file#browser-support) for scalability and flexibility. &nbsp;&nbsp;&nbsp;&nbsp; [<img src="https://img.shields.io/badge/Get%20started-F0F0F0?style=for-the-badge&logo=adobe&logoColor=%23FF0000"/>](https://opensource.adobe.com/spectrum-css/get-started.html) &nbsp; [<img src="https://img.shields.io/badge/Storybook-F0F0F0?style=for-the-badge&logo=storybook&logoColor=%23FF4785"/>](https://opensource.adobe.com/spectrum-css/) ## Using Spectrum CSS The preferred method of using Spectrum CSS relies on custom properties to swap out variables for different themes and contexts. This results in the lowest bundle sizes and is one of the simpler approaches. Want to get a component up and running as soon as possible? Check out the [quick start guide](https://github.com/adobe/spectrum-css/blob/main/.github/QUICK-START.md). ### Functionality Spectrum CSS is CSS-only, implementing only the interactivity that can be done with pure CSS. We do include some lightweight JS-based interaction for demonstration purposes only in our [Storybook](https://opensource.adobe.com/spectrum-css/). Spectrum CSS should only be used by implementations of Spectrum, or very simple applications that only need things like typography, checkboxes, text fields, etc. Adobe maintains separate libraries written with [web components](https://opensource.adobe.com/spectrum-web-components/) and [React](https://react-spectrum.adobe.com/react-spectrum/index.html) that work in partnership with Spectrum CSS to create fully interactive Spectrum components. The [Spectrum Web Components](https://opensource.adobe.com/spectrum-web-components/) library directly imports Spectrum CSS and optimizes it for use with web components. ### Installing components Each component is released on npm as a separate, individually versioned package inside of the [@spectrum-css](https://www.npmjs.com/org/spectrum-css) org. To incorporate Spectrum CSS into your project, you install the components you need along with any peer dependencies you need for your implementation. Most peer dependencies are optional and can bring additional features when installed along with a component. For example a button can be rendered with or without an icon; so if your use-case leverages an icon with your button, you'll want to install icon as a peer dependency. ```shell yarn add -DW @spectrum-css/tokens @spectrum-css/typography @spectrum-css/page @spectrum-css/icon @spectrum-css/button ``` Installed components will be available in the `node_modules/@spectrum-css/` folder of your project. All components in this library have a peer dependency on [`@spectrum-css/tokens`](tokens), which is a local package that serves up the [Spectrum design tokens](https://github.com/adobe/spectrum-tokens) as CSS custom properties (via [Style dictionary](https://amzn.github.io/style-dictionary/#/)). These custom properties are leveraged in all components to create a cohesive visual language and to allow for easy theming. If you choose not to use the provided `@spectrum-css/tokens` package, you must define your own custom properties or your components will render with a significant number of missing styles. When overriding certain styles is necessary, modifying styles is supported through the use of component-specific `--mod` prefixed properties. [More on this below](https://github.com/adobe/spectrum-css?tab=readme-ov-file#modifying-components). ### Using components in your project Spectrum CSS components have build output that is designed to be used in a variety of ways: - `index.css` - _Preferred and most commonly used to incorporate Spectrum CSS into a project_. This file includes the component's styles and variable definitions. In this version, token-driven CSS properties<sup>[1](#token-footnote)</sup> are mapped to empty `--mod` prefixed variables (for customization) with a fallback to variables prefixed with `--spectrum` (sourced from the design tokens). - This file loads the `.spectrum`, `.spectrum--legacy`, and `.spectrum--express` contexts which are used to toggle components between different [visual styles](https://github.com/adobe/spectrum-css?tab=readme-ov-file#visual-language). The `.spectrum` context is the default. - `index-base.css`: This file mimics the `index.css` output, but does not include the `.spectrum` or `.spectrum--express` contexts. - If your product only requires the `.spectrum` context, you can use `index-base.css` plus `themes/spectrum-two.css` from the `themes` directory to render the default Spectrum visual language. - The `.spectrum--legacy` context represents the previous version of Spectrum (also known as Spectrum 1). This means if you only want to use the legacy context, you should load `themes/spectrum.css`. **deprecated** - The `.spectrum--express` context represents the subtheme of Spectrum 1 called Express . This means if you only want to use the Express context, you should load `themes/express.css`. **deprecated** - This approach can also be used when you have defined and written your own visual language and only need the base component styles from Spectrum CSS. To wire up your own visual language, you would need to define your own custom properties that match those defined in the `themes/spectrum-two.css` assets. - `index-theme.css`: This file provides only the visual language for a component. It is used in conjunction with `index-base.css` and when loaded together, provides the same result as using `index.css` by itself. <sup><a name="token-footnote">1</a></sup>: Token-driven CSS properties are properties whose values are mapped to a value in the `@spectrum-css/tokens` package. These values represent design-language and are meant to be used across platforms. In contrast, properties specific to web-based implementations will not have a token value assigned, so not all CSS properties will use custom properties. #### Including assets Start by including the base set of variables: ```css /* Include tokens */ @import "node_modules/@spectrum-css/tokens/dist/index.css"; /* For components with no other contexts available, load the index.css file from the component's package. These are components that do not have a spectrum or express context available. */ @import "node_modules/@spectrum-css/page/dist/index.css"; @import "node_modules/@spectrum-css/typography/dist/index.css"; @import "node_modules/@spectrum-css/icon/dist/index.css"; /* Recommended: For components with multiple contexts available, if you want access to all contexts, load the index.css file, which includes all contexts and component variables. */ @import "node_modules/@spectrum-css/button/dist/index.css"; /* If you only need the spectrum visual context: For components with multiple contexts available, load only the spectrum context by sourcing index-base.css and the spectrum theme from the themes directory. */ @import "node_modules/@spectrum-css/button/dist/index-base.css"; @import "node_modules/@spectrum-css/button/dist/themes/spectrum.css"; ``` Tokens values are mapped to context-specific classes which can be applied to the `<html>` element or any place in your DOM where you wish to encapsulate or alter the visual language of your Spectrum components. All contexts you want to use must be defined in order to load all the appropriate custom properties for the components you are using. #### Global variables ##### Visual language - `.spectrum` - The default visual language for Spectrum CSS; represents the Spectrum 2 foundations visual language. - `.spectrum--legacy` - The legacy Spectrum 1 visual language. _This visual language will be deprecated in Spectrum 2_. - `.spectrum--express` - A variant of the standard visual language. _This visual language will be deprecated in Spectrum 2_. ##### Scales Scales represent the browsing context of the user. They are used to adjust the size of components to improve readability and usability on different devices. - `.spectrum--medium` - The default scale for Spectrum CSS, used for desktop and tablet devices - `.spectrum--large` - A larger scale for Spectrum CSS, used for mobile devices and other small screens to create a more touch-friendly experience ##### Themes (colorstops) Themes represent the color scheme of the user's browsing context. They are used to adjust the color of components to improve readability and usability in different environments. - `.spectrum--light` - The default theme for Spectrum CSS, used for light mode - `.spectrum--dark` - A darker theme for Spectrum CSS, used for dark mode Other themes are available but are in the process of being deprecated and should not be used in new projects. #### Context example Put together, we would define the context for our application in the following way: ```html <html class="spectrum spectrum--medium spectrum--light"></html> ``` To switch to Express, **add** the `.spectrum--express` class to the `<html>` element: ```html <html class="spectrum spectrum--medium spectrum--light spectrum--express" ></html> ``` Note the `spectrum--legacy` or `spectrum--express` class is added to the existing classes; `spectrum` should always be present to ensure the correct visual language is loaded. Because CSS custom properties honor the cascading nature of CSS, you can infinitely nest different contexts. For example, you could have a `.spectrum--dark` context inside of a `.spectrum--light` context, and components will honor the innermost context. ### Modifying components You can override variables and modify Spectrum CSS' look and feel by re-defining the custom properties in context. Look for the **Custom Property API** section in each component to determine which custom properties you can override. See [Action Button for a complete example](https://opensource.adobe.com/spectrum-css/actionbutton.html#custompropertiesapi). ### Importing UI icons Some components require certain "UI icons" to render. These icons are released within the [`@spectrum-css/ui-icons`](https://www.npmjs.com/package/@spectrum-css/ui-icons) package and are used by components like `@spectrum-css/icon` and `@spectrum-css/actionbutton`. Based on [which scales](https://github.com/adobe/spectrum-css?tab=readme-ov-file#scales) you'll be using, you can choose to load different files: - `spectrum-css-icons.svg` - Both medium and large icons for responsive UIs that support both `.spectrum--medium` and `.spectrum--large` - `spectrum-css-icons-medium.svg` - Medium icons only, supports `.spectrum--medium` only - `spectrum-css-icons-large.svg` - Large icons only, supports `.spectrum--large` only **Note:** If you're using `spectrum-css-icons.svg`, be sure to add `.spectrum--medium` or `.spectrum--large` to the `<html>` element, or you'll see both medium and large icons at once. ### Importing workflow icons If your app has any level of complexity, you'll need "workflow" icons to indicate actions. These icons are not required to render the base components, and instead are used within buttons or menu items for actions like share, play, justify, save, etc. These icons are released within the [`@adobe/spectrum-css-workflow-icons`](https://www.npmjs.com/package/@adobe/spectrum-css-workflow-icons) package. Visit the [Spectrum workflow icon list](https://spectrum.adobe.com/page/icons/) and click on any icon to get the SVG markup. ### Language support To take advantage of locale specific changes such as placeholders not italicizing Japanese, your application should specify a [`Content-Language` response header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Language) or set the [`lang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang). In addition, you should set the `dir` attribute for components to render correctly. For English, a left-to-right language: ```html <html lang="en" dir="ltr"></html> ``` For Arabic, a right-to-left language: ```html <html lang="ar" dir="rtl"></html> ``` ### Browser support We maintain a modern codebase that supports the latest two versions of evergreen web browsers. The current list of browsers officially supported by Spectrum CSS can be found in the browserslist section of the project's [package.json file](https://github.com/adobe/spectrum-css/blob/main/package.json). This setting is used by the build tools when the source files are built. If you require additional browser support for your project, the CSS can be processed further with your chosen tools. - latest 2 Edge versions - latest 2 Chrome versions - latest 2 Firefox versions - latest 2 Safari versions - latest 2 iOS versions ### Optimizing Spectrum CSS Spectrum CSS is designed to be as modern and flexible as possible, and as such, leaves room for consumers to optimize in their own way. There are many tools and techniques you can use to optimize CSS for your project such as tree shaking, purging, and minification. If you are loading the entire set of `@spectrum-css/tokens` for example, you can safely tree shake the tokens to only include the variables you are using, often leading to a significant reduction in file size. ## Contributing A very special thank you to all of our [contributors](https://github.com/adobe/spectrum-css/graphs/contributors) without whom this project would not be possible. Want to join the team? Check out the [contributing guidelines](.github/CONTRIBUTING.md) to get started. ## Tasks The following tasks are available: | Command | Description | Examples | | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | | `clean` | Cleans all output files for the project and all components | `yarn clean` | | `build` | Performs a build of all components | `yarn build` | | `bundle` | Creates a bundled asset for use in demos or development environments | `yarn bundle` | | `start` | Performs a local development build of Storybook | `yarn start` | | `compare` | This compares the current version of components with the previous versions published to NPM and output a list of all the changes that have been made. This is useful for reviewing changes before a release. The information is provided in the command-line output as well as in a simple web page that is opened in your default browser upon completion. The web page includes links to the visual diffs for each component when the file sizes have changed. <ul><li>Components with no changes are not included in the output.</li><li>To run comparisons on one or multiple components, `compare` accepts a list of components as arguments. For example, `yarn compare button` will compare the current version of the button component with the previous version published to NPM. `yarn compare button checkbox` will compare the current version of the button and checkbox components with the previous versions published to NPM.</li><li>Named components should be space-separated.</li><li>Running `compare` with no inputs will automatically run against all packages.</li></ul> | `yarn compare`<br/>`yarn compare accordion`<br/>`yarn compare accordion actionbutton` | | `lint` | Provides helpful updates and warnings for a component's package.json file. This helps keep all components in alignment. Use `format` to automatically fix any issues that are found. To run on a single component, use `yarn linter accordion` (where `accordion` is the name of the component or components you want to lint). | `yarn lint`<br/>`yarn linter accordion`<br/>`yarn linter accordion actionbutton` | | `format` | Provides helpful updates and warnings for a component's package.json file. This helps keep all components in alignment. To run on a single component, use `yarn formatter accordion` (where `accordion` is the name of the component or components you want to lint). | `yarn format`<br/>`yarn formatter accordion`<br/>`yarn formatter accordion actionbutton` | | `refresh:env` | This copies values for the project's `.env` file (an asset never committed to the repo as it contains login secrets) by using the `.env.example` file as a template. This script is useful when you need to update the `.env` file with new values from the `.env.example` file or when you checkout or clean the repo and need to restore the `.env` file. | `yarn refresh:env` | | `yarn constraints` | This command will list out any changes suggested by the settings defined in `yarn.config.cjs`. The goal of this tool is to more easily allow us to add, update, or remove properties to/from all package assets. Add the `fix` flag to apply the suggested changes. | `yarn constraints` or `yarn constraints --fix` | ## Troubleshooting As of February of 2024, the Spectrum CSS project has moved to a new tokens system (@spectrum-css/tokens instead of @spectrum-css/vars). If you are using Spectrum CSS and see that your styles are off, or not applying at all, ensure that you are using the correct tokens package for the component.

CSS Frameworks & UI Kits Design Systems & Tokens
1.3K Github Stars
spectrum-design-data
Open Source

spectrum-design-data

Note: for [Spectrum 2](https://s2.spectrum.adobe.com/) token data has been graduated to the `main` branch. If you need access to the S1 data, use the [`s1-legacy` branch](https://github.com/adobe/spectrum-design-data/tree/s1-legacy) and `v12.x.x` packages on [NPM](https://www.npmjs.com/package/@adobe/spectrum-tokens?activeTab=versions). The [Spectrum token visualizer](https://opensource.adobe.com/spectrum-design-data/visualizer/) shows the token data for S1. For Spectrum 2 data, use [opensource.adobe.com/spectrum-design-data/s2-visualizer/](https://opensource.adobe.com/spectrum-design-data/s2-visualizer/). # Spectrum Tokens Monorepo This repo uses: * [pnpm](https://pnpm.io/) for package management * [moon](https://moonrepo.dev/moon) to manage task running * [Changesets](https://github.com/changesets/changesets) for automated versioning and releasing * [Prettier](https://prettier.io/) for code formatting/linting * [commitlint](https://commitlint.js.org/) and [Convetional Commits](https://www.conventionalcommits.org/en/v1.0.0/) to standardize commit messages * [husky](https://typicode.github.io/husky/) to automate formatting of committed files and linting of commit messages Packages in this monorepo: ## Core Packages * [Spectrum Tokens](packages/tokens/) design tokens for Spectrum, Adobe's design system. * [Spectrum Component Schemas](packages/component-schemas/) JSON schemas for validating Spectrum component APIs and properties. ## Documentation & Visualization * [Spectrum Token Visualizer Tool](docs/visualizer/) a visualizer for inspecting S1 tokens. Published as a [static site](https://opensource.adobe.com/spectrum-design-data/visualizer/). * [Spectrum Token Visualizer Tool S2](docs/s2-visualizer/) a version of the visualizer that shows the Spectrum 2 data. Published as a [static site](https://opensource.adobe.com/spectrum-design-data/s2-visualizer/). * [Spectrum S2 Tokens Viewer](docs/s2-tokens-viewer/) an enhanced token viewer with component usage analysis for Spectrum 2 tokens. * [Spectrum Tokens Docs](docs/site/) a static site to show the component options API and other token data. * [Release Timeline Visualization](docs/release-timeline/) interactive charts showing release frequency and development activity patterns. Published as a [static site](https://opensource.adobe.com/spectrum-design-data/release-timeline/). * [Spectrum 2 Documentation](docs/s2-docs/) comprehensive component guides and design principles from s2.spectrum.corp.adobe.com. ## Development Tools * [Component Options Editor](tools/component-options-editor/) Figma plugin for authoring and editing Spectrum component option schemas with visual UI and JSON validation. * [Spectrum Token Diff Generator](tools/diff-generator/) a library and cli tool that reports changes made between two schema/releases/branches. * [Optimized Diff Engine](tools/optimized-diff/) high-performance diff algorithm for large token datasets. * [Release Analyzer](tools/release-analyzer/) tool for analyzing release history and generating data for change frequency visualization. * [Token Changeset Generator](tools/token-changeset-generator/) automates creation of changeset files from token diff analysis. * [Transform Tokens JSON](tools/transform-tokens-json/) utilities for merging and transforming token data between formats. * [Token Manifest Builder](tools/token-manifest-builder/) generates manifest files for token distribution. * [Spectrum Design Data MCP](tools/spectrum-design-data-mcp/) Model Context Protocol server providing AI assistants with structured access to Spectrum design system data. * [S2 Docs MCP](tools/s2-docs-mcp/) MCP server providing AI assistants with access to Spectrum 2 component documentation and design guidelines. ## SDK & TUI * [design-data](sdk/cli/) unified CLI and interactive TUI — validate, resolve, diff, query, and migrate tokens from the command line; run bare (`design-data`) to launch the interactive TUI (command palette, cascade resolver, validator, four-screen authoring wizard). The TUI library lives in [sdk/tui/](sdk/tui/). ## Setup monorepo locally 1. Install pnpm using [this guide](https://pnpm.io/installation). 2. Install dependencies ```bash pnpm i ``` ### Build all packages locally Run build script ```bash pnpm moon run :build ``` ### Run all tests locally ```bash pnpm moon run :test ```

Design Systems & Tokens
137 Github Stars
lit-mobx
Open Source

lit-mobx

[![Known Vulnerabilities](https://snyk.io/test/github/adobe/lit-mobx/badge.svg)](https://snyk.io/test/github/adobe/lit-mobx) # lit-mobx Mixin and base class that allow easy usage of mobx observables with [`lit`](https://lit.dev/). The mixin implementation is based heavily on the work of Alexander Weiss in his [`mobx-lit-element`](https://github.com/alexanderweiss/mobx-lit-element) implementation. This has been rewritten to support multiple forms of usage (mixin, or base class) as well as to be based on typescript to get type definitions. ## Installation As a dependency: ``` npm install --save @adobe/lit-mobx lit mobx ``` ## LitElement 2.0 Usage This library has been updated to the latest version of Lit which we highly recommend you update to. However if you wish to continue using LitMobx with [LitElement 2.0](https://lit-element.polymer-project.org/guide) then install the 1.0 major version: ``` npm install --save @adobe/lit-mobx@^1.0.0 ``` We will backport any security patches (though don't expect there to be any) in this major version as necessary. ## Demo ``` npm install npm run demo ``` ## Usage See the [JavaScript](https://stackblitz.com/edit/lit-mobx-demo?file=index.js) and [TypeScript](https://stackblitz.com/edit/lit-mobx-typescript?file=index.ts) example projects on StackBlitz. See [this example](https://stackblitz.com/edit/lit-mobx-typescript-mobx6?file=index.ts) for a demonstration of usage with Mobx v6 in Typescript without the use of decorators. ```typescript import { html, TemplateResult } from 'lit'; import { customElement, LitElement } from 'lit/decorators.js'; import { observable, action } from 'mobx'; import { MobxLitElement } from '@adobe/lit-mobx'; // create a mobx observable class Counter { @observable public count = 0; @action public increment() { this.count++; } } // create instance that can be shared across components const counter = new Counter(); // create a new custom element, and use the base MobxLitElement class // alternatively you can use the MobxReactionUpdate mixin, e.g. `class MyElement extends MobxReactionUpdate(LitElement)` @customElement('my-element') export class MyElement extends MobxLitElement { private counter = counter; // any observables accessed in the render method will now trigger an update public render(): TemplateResult { return html` Count is ${this.counter.count} <br /> <button @click=${this.incrementCount}>Add</button> `; } private incrementCount() { this.counter.increment(); } } ``` For further examples see the [demo folder](./demo). NOTE: observables are only hooked for updating the render function if those observables are directly used within the render function. The implementation of this library is such that we essential wrap the render function in an `autorun` block to hook these observables for re-running render. If you wish to response to an observable property to calculate some other result that then itself is used in the render function, then you need to use the regular MobX methods for observability in a property changed callback or some other lifecycle function to setup that observation and the write to a property in your component that is appropriately decorated to drive Lit's regular update cycle. ## Custom Reaction In some rare cases applications may need to have multiple different major versions of Mobx within a single app. This can lead to issues where the version of mobx used in various places needs to be specifically imported from aliased versions of mobx, e.g. aliasing `mobx 6.x` to `mobx6`. To help support these cases lit-mobx provides the custom implementation of the MobxReactionUpdate mixin, `MobxReactionUpdateCustom`, that supports taking the `Reaction` constructor as a second argument. This allows the user to define which version of mobx to pass, and ensures that no side effects are caused by lit-mobx importing `mobx` directly. Example usage: ```typescript import { MobxReactionUpdateCustom } from '@adobe/lit-mobx/lib/mixin-custom.js'; // import your specific mobx version import { Reaction } from 'mobx6'; // and pass it to the mixin to create your own mobx lit element base class class Mobx6LitElement extends MobxReactionUpdateCustom(LitElement, Reaction) {} ``` ### Contributing Contributions are welcomed! Read the [Contributing Guide](./.github/CONTRIBUTING.md) for more information. ### Licensing This project is licensed under the Apache V2 License. See [LICENSE](LICENSE) for more information.

JavaScript Libraries & Components
271 Github Stars