- 
                Notifications
    You must be signed in to change notification settings 
- Fork 8
feat: tabs data attrs #335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v2-migration
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import Hero from "./examples/hero"; | ||
| import Vertical from "./examples/vertical"; | ||
| import Disabled from "./examples/disabled"; | ||
|  | ||
| # Tabs | ||
|  | ||
| A set of layered sections of content, known as tab panels, that are displayed one at a time. | ||
|  | ||
| <Hero /> | ||
|  | ||
| ## Vertical | ||
|  | ||
| <Vertical /> | ||
|  | ||
| ## Disabled | ||
|  | ||
| <Disabled /> | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -24,6 +24,8 @@ type DataAttributeState = | |
| | "empty" | ||
| | "orientation"; | ||
|  | ||
| type OrientationValue = "vertical" | "horizontal"; | ||
|  | ||
| /** | ||
| * Generate positive and negative variant CSS for a given state | ||
| * | ||
|  | @@ -60,6 +62,29 @@ function generateVariant(state: DataAttributeState): string { | |
| );`; | ||
| } | ||
|  | ||
| /** | ||
| * Generate orientation-specific variant CSS | ||
| * | ||
| * @param orientation - The orientation value ("vertical" or "horizontal") | ||
| * @returns CSS string with @custom-variant declarations | ||
| */ | ||
| function generateOrientationVariant(orientation: OrientationValue): string { | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to re-think this approach in a more general sense, like generateValueVariant Also: /**
 * ui-orientation-vertical: Apply styles when nearest component scope has data-orientation="vertical"
 * Automatically scopes to prevent nested components from inheriting state
 */
@custom-variant ui-orientation-vertical (
  /* Descendant of scope with data-orientation="vertical", stops at nearest scope boundary */
  [data-qds-scope][data-orientation="vertical"] > &,
  [data-qds-scope][data-orientation="vertical"] > :not([data-qds-scope]) &,
  /* Direct match on element itself */
  [data-orientation="vertical"]&
);
/**
 * ui-orientation-horizontal: Apply styles when nearest component scope has data-orientation="horizontal"
 * Automatically scopes to prevent nested components from inheriting state
 */
@custom-variant ui-orientation-horizontal (
  /* Descendant of scope with data-orientation="horizontal", stops at nearest scope boundary */
  [data-qds-scope][data-orientation="horizontal"] > &,
  [data-qds-scope][data-orientation="horizontal"] > :not([data-qds-scope]) &,
  /* Direct match on element itself */
  [data-orientation="horizontal"]&
);This would quickly get messy needing to create a custom variant for every possible value. Maybe they can provide a "arbitrary variant" the same way they provide a value? If we don't want to come at it from that angle, I think it would make sense to add two new modifiers: 
 Also making sure that we add the not-x versions as well so people can compose them as they would expect. | ||
| const variantName = `ui-orientation-${orientation}`; | ||
| const dataAttr = `data-orientation="${orientation}"`; | ||
|  | ||
| return `/** | ||
| * ${variantName}: Apply styles when nearest component scope has ${dataAttr} | ||
| * Automatically scopes to prevent nested components from inheriting state | ||
| */ | ||
| @custom-variant ${variantName} ( | ||
| /* Descendant of scope with ${dataAttr}, stops at nearest scope boundary */ | ||
| [data-qds-scope][${dataAttr}] > &, | ||
| [data-qds-scope][${dataAttr}] > :not([data-qds-scope]) &, | ||
| /* Direct match on element itself */ | ||
| [${dataAttr}]& | ||
| );`; | ||
| } | ||
|  | ||
| /** | ||
| * Generate all variants | ||
| */ | ||
|  | @@ -80,6 +105,8 @@ export function generateAllVariants(): string { | |
| "orientation" | ||
| ]; | ||
|  | ||
| const orientations: OrientationValue[] = ["vertical", "horizontal"]; | ||
|  | ||
| const header = `/** | ||
| * QDS UI State Variants | ||
| * | ||
|  | @@ -90,13 +117,18 @@ export function generateAllVariants(): string { | |
| * ui-checked:bg-blue-500 | ||
| * not-ui-disabled:opacity-100 | ||
| * ui-open:rotate-180 | ||
| * ui-orientation-vertical:border-r | ||
| * ui-orientation-horizontal:border-b | ||
| * | ||
| * Generated by: docs/generate-ui-variants.ts | ||
| * DO NOT EDIT MANUALLY - Run the generator script to update | ||
| */ | ||
| `; | ||
|  | ||
| const variants = states.map((state) => generateVariant(state)).join("\n\n"); | ||
| const orientationVariants = orientations | ||
| .map((orientation) => generateOrientationVariant(orientation)) | ||
| .join("\n\n"); | ||
|  | ||
| return `${header}\n${variants}`; | ||
| return `${header}\n${variants}\n\n${orientationVariants}`; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems like something we would just have a boolean for, not needing a bind