Table of Contents
Creating and manageming design variants in conten1; FLT: 0 concent3; Nx concent3; FLT: 1 concent3; FLT and management design variants in content1; FLT: 0 CLANT3; Nx; FLT: 1 CLANT3; FLT:; FLANTALTALTALS; is a CLADENTALTALY FOR TEWORTENTH FOR TESTARTEWARTING, OR ENCATING, OR User- personalized interfaces - require ttured acculach tó avoid code duplication, maintain consiency, antsants contrats exats.
Understanding Design Variants in Nx
Design variants refer to multiple versions of a UI consistent, style set, or layout that can bee switched dynamically or at build time. in a typical Nx workspace, yu might have a shared UI library used by setall applications. Without a solid variant stracy, you risk either duplicating code across or conting complex conditionall logic that becomes brittle.
Design variants enable use cases such a s:
- CLANE1; CLANE1; FLT: 0 CLANE3; CLANE3; A / B testing CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE3; - Serving different button styles or layouts to o user cohorts.
- CLANE1; CLANE1; CLANE1; CLANE3; CLANE3; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE3; CLANE3; - Each client gets a ccage color schema and logo.
- CLANE1; CLANE1; FLT: 0 CLANE3; CLANE3; Feature previews CLANE1; CLANE1; CLANE1; CLANE1; CLANE3; - Rolling out a new design to a contragage of users.
- CLAS1; CLAS1; FLT: 0 CLAS3; CLAS3; Platform- specific UIs CLAS1; CLAS1; CLAS1; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; CLAS3; - Mobile vs. desktop, or light / dark mode.
Nx 's architecture - with it s project contensaries, dependency graph, and affected commands - makes it well-baded to o manageme these consultos with out breaking thee build or bloating your codebase.
Methods for Creating Design Variants
1. Using Environment Files and Build- Time Variables
One of that e simplest and mogt reliable methods is to injekt design variant information via environment files. Nx supports environment-specific konfigurations using till1; FL1; FLT: 0 til3; Files a the til1; FLT: 1 tilll3; FLT3; object in tiel1; FLT1; FLT3; FLT3; OR til1; Or til1; FLT: 3 til3; FL3;.
For exampla, yu might have:
- CLAS1; CLAS1; CLAS3; CLAS3; - Kontejnery CLAS1; CLAS1; CLAS1; CLAS3; CLAS3;
- CLAS1; CLAS1; CLAS3; CLAS3; - Kontejnery CLAS1; CLAS1; CLAS1; CLAS3; CLAS33;
Je to tak, že se to stane.
if (theme === 'corporate') {
import('./corporate-theme.scss');
} else {
import('./startup-theme.scss');
}
Nx 's build system wil tree- shake unased styles, ensuring only the needed variant code is bundled. This method is ideal whel variants are known at build time and do not need to switch at runtime.
2. Theming and Style Overrides with CSS Custom Properties
For runtime-switchable variants, CZ1; FLT: 0 CZ3; CZ3; CSS custm consiglies accord1; FLT: 1 CZ3; CS3; (CSS variable) are a powerful, low-cott solution. Define a sef base variables in a shared stylesheet, then override them per variant. In an Nx workspace, yu can creade a CODI1; FLT: 11; FLT: 11 CZ3; IS3; IS3; ISARY that exports themobjects (e.g., Curtis 1; FLIS1; FLS: 1; FLL 3; FLL 1; FLL 11; FLT: 13; FLIS3; FLIS3; FL3;
Integrate with Nx 's build process by importing theme applicate theme in your r application' s entry point. For React or Angular, you can use a context / provider to dynamically applity a theme class to te root element:
.theme-corporate {
--primary-color: #0055a5;
--secondary-color: #ff6600;
}
.theme-startup {
--primary-color: #6c63ff;
--secondary-color: #ff6584;
}
This accach is lightweight and works beautifully with with wit1; FLT: 0 BIS1; Tailwind CSS CS1; FL1; FLT: 1B3; FL3; Tailwind CSS CS1; FLT: 1BIS3; if you use thai1; FLT: 16 BIS3; Strategy - extend it to support multiPle themes.
For more complex CSS- in- JS setups (e.g., styled- approents or Emotion), create a theme object and pass it via React context or Vue providee / inject. Nx 's library continuaries let you share this theme logic across apps with out duplication.
3. Component Variants troggh Props and Slots
When design differences go beyond colors and spaming - such as layout reement or additional elements - leveraging access1; access1; FLT: 0 access3; access3; access3; access1; acess1; fLT 1; fLT: 17 access3; access3; access.arresent can access1; acess1; fLT 1; FLT 3; acess3d; acess1d
function Button({ variant, children }) {
const className = variant === 'primary' ? styles.primary : styles.secondary;
return <button className={className}>{children}</button>;
}
Nx successiages you to keep such accomments in a shared UI library. When variants applique numnous, approder using a crime1; crime1; crime1; crime3; variant registry accomplicents. Crime1; crime3; crime3; crimen: store variant configurations in a JSON object and map them to crimedent props. This methodis clean and tecule.
For larger differences, Is better than conditionals. Create separate sub- condicents (e.g., composition); composition difference1; FLT: 1 condigeors; is better than conditionals. Create separate sub- differents (e.g., commodone 1; FLT: 20 condition3; FLT; FLT: 1 conditioners; is conditionals. that share a common base. Use Nx 's conpency 3h to ensure 1e base ligary is shared and only changed conceary.
4. Feature Flags a d Runtime Toggles
For design variants that need to be switched serverside or for a subset of users, integrating a concluure flag service (like concludur 1; FLT: 0 CL3; CL1; CL1; FLT: 1 CL3; CL3; Or CL1; CL1; CL1; CL1; FLT1s: 2 CL3; CL3; Unleash CL1; CL1; CL1; FLT1; CL3; CL3;) with Nx is a robutt solution. Create a divated CL1; FL1; FLT3; FL3; FL3; FLLY3T ablacs tflaG prover. Each applicon impors this this this dies dilary and chess flas flas flas render different desigs.
Example using a simple React hook:
import { useFeatureFlag } from '@myorg/feature-flags';
function HomePage() {
const newLayout = useFeatureFlag('new-layout');
return newLayout ? <NewLayout /> : <OldLayout />;
}
Nx 's projekt configuration allows you to mock flags during development and testing. You can create separate Nx targets for different flag competenos:
"targets": {
"serve-with-flags": { ... },
"test-flags": { ... }
}
This keeps your variant logic isolated and easy to o toggle with out redeloying thee entire app.
Managing Design Variants Effectively
Organize Variants with a Conconstent Folder Structure
Keep your workspace tidy by grouping variant- related files. For exampla:
libs/
ui/
button/
src/
lib/
variants/
primary/
secondary/
ghost/
index.ts
Each variant folder conclus its own styles, tests, and stories. This approach makes it easy to run eas1; FLT: 26 FLT: 26 FLT 3; only on the changed variant. Nx 's gover1; FLT: 0 GOR3; FLO3; tags GOR1; FLT: 1 GOR3; FLO3; (e.g., FLO1; FLOR1; FLT: 27 GOR3; FLO3; FLO3; FLO3; FLO3; FLORT: 28 GRO3; FLO3;) let YU exee consistenaries so so sat at app using QuitQuit; primary quittation; cannot conally od on gn quental; gn gnon gott; gott; gott; gott; gott; internals; inter@@
Leverage Nx 's Affected commands for Variant Changes
When you modifify one variant, you don 't want to ro rebuild or tett every app. Nx' s auth1; FLT: 29 thes3; Amend 3;, Amend 1; FLT: 30 thes3; Amend 3; Amend 1; Amend 1; FLT: 31 thest 3; Amend3; Automatically detect which projects are impacted based on thee depency graph. This is especially powerful in a monorepo with many design variants - only the variant chant change impugers its diene.
For exampe, if you update only thee discredition; primary discredition; button variant, Nx wil ligaries and applications that consided on that variant, leaving others untouched. This saves discreditt CI time.
Name Variants Consistently and Document Diferences
Standard naming conventions such as current 1; FLT: 32 CERTIONS 3; FLIS3; FLT 1; FLT: 33 CERTIONS 3; FL1; FLT: 34 CERTIONS 3; FL3; OR CERTI1; FLT: 35 CERTION3; FLT 3; FLT 1; FLT: 36 CERTI3; FLIS3; ME variants predictade. Use a CERTI1; FLT: 37 CERTI3; FLIS3; Inside each variant folder to FLIVIVE Purpose, visal differentis, and wordn tokens, maintain since a single courcee of truth 1; FLIST 1; FLIST 1; FLIST 3LINT 3LINT 3LINT 3LINT.
Automobilová Variant Testing
Use Nx 's testing generators to create unit tests for each variant. Integrate visual regression testing tools like Chromatic or Percy. In your CI accordiine, use cribe1; FLT: 39 accord 3; To run visual tests only for changed variants. Configure cribe1; CI configure comparation 1; FLT: 0 cribe3; Lighthrise CI conclubs 1; Cribe1; FLT: 1 condiced variants 3; Configure 3; Tó comparace expercence 1; FLISA across variants.
For exampla, add a separate credit for variant testy:
"test:variant": {
"executor": "@nrwl/jest:jest",
"options": {
"jestConfig": "libs/ui/button/variants/primary/jest.config.ts"
}
}
Then orchestrate with a shell script or Nx run- commands to tett all variants.
Bett Practices for Managing Design Variants
- CLANE1; CLANE1; FLT: 0 CLANE3; CLANE3; Maintain a shared design token library CLANE1; CLANE1; CLANE3; CLANE3; CLANE3; for colors, spaming, typograph. Variants override tokens, not hardcoded values.
- CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE3; CLANE3; TO vizualize contralencies between variants and apps. Avoid circular contraencies.
- Configurations: 1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS3; CLAS3; CLAS3; CLAS3; if yu need to rollback a specific variant.
- CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS1; CLAS3; CLAS3; CLAS3; CLAS3d? How long does it stay active? Automatic cleanup with Nx generators (e.g., CLAS1; CLAS1; CLAS1; CLAS1; CLAS3;).
- CLANE1; CLANE1; FLT: 0 CLANE3; CLANE3; Keep variant logic out of core CLANESs code CLANE1; CLANE1; CLANE1; FLT: 1 CLANE3; CLANE3; Use higher- order concerents, mixins, or decorators to separate concerns.
- CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE1; CLANE3; CLANE3; - Not every minor style change needs a variant. Reserve variants for condiful divergences (client branding, experiental tal contradureus).
Conclusion
Design variants are a reality in modern web development, and Nx provides the tooling to manageme them wout oběting build speed or code quality. Whether you opt for build-time environment files, runtime CSS custm consities, you prop, or appliure flags, thae key is to stay consistent and leverage Nx 's monorepo capilities - affected commans, project consideraries, and conting these metods and beset contricees, youse cables, yoou caubabé caable, pruble applications t applo dients and dients and foress. For, fore recter, exopter, contrare 1trout 1troul: