-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add text as new component (#26090)
* add text as a new component * update main.js to .cjs format for esm due to require syntax * update style rules to align with FUI react v9, export text options, update stories to leverage object.keys of options * export text, update node resolution to 16 and fix object.keys for size to object.values * prettier style files, may need to revert if it does not play nice with selectors * update display for host to ensure we can layout the element properly margin, etc... * update latest FAST packages * leverage ValuesOf type helper
- Loading branch information
1 parent
7c94cbd
commit 5e3ba35
Showing
22 changed files
with
649 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
change/@fluentui-web-components-06188225-69da-4cf6-918c-932a9ceab1b3.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "add text as a new component", | ||
"packageName": "@fluentui/web-components", | ||
"email": "chhol@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import type { FASTElement, ViewTemplate } from '@microsoft/fast-element'; | ||
import type { AnnotatedStoryFn, Args, ComponentAnnotations, StoryAnnotations } from '@storybook/csf'; | ||
|
||
/** | ||
* A helper that returns a function to bind a Storybook story to a ViewTemplate. | ||
* | ||
* @param template - The ViewTemplate to render | ||
* @returns - a function to bind a Storybook story | ||
*/ | ||
export function renderComponent<TArgs = Args>( | ||
template: ViewTemplate, | ||
): (args: TArgs) => Element | DocumentFragment | null { | ||
return function (args) { | ||
const storyFragment = new DocumentFragment(); | ||
template.render(args, storyFragment); | ||
if (storyFragment.childElementCount === 1) { | ||
return storyFragment.firstElementChild; | ||
} | ||
return storyFragment; | ||
}; | ||
} | ||
|
||
/** | ||
* A helper that returns a function to bind a Storybook story to a ViewTemplate. | ||
*/ | ||
export type FASTFramework = { | ||
component: typeof FASTElement; | ||
storyResult: FASTElement | Element | DocumentFragment; | ||
}; | ||
|
||
/** | ||
* Metadata to configure the stories for a component. | ||
*/ | ||
export type Meta<TArgs = Args> = ComponentAnnotations<FASTFramework, Omit<TArgs, keyof FASTElement>>; | ||
|
||
/** | ||
* Story function that represents a CSFv3 component example. | ||
*/ | ||
export declare type StoryObj<TArgs = Args> = StoryAnnotations<FASTFramework, TArgs>; | ||
|
||
/** | ||
* Story function that represents a CSFv2 component example. | ||
*/ | ||
export declare type StoryFn<TArgs = Args> = AnnotatedStoryFn<FASTFramework, TArgs>; | ||
|
||
/** | ||
* Story function that represents a CSFv2 component example. | ||
* | ||
* NOTE that in Storybook 7.0, this type will be renamed to `StoryFn` and replaced by the current `StoryObj` type. | ||
*/ | ||
export declare type Story<TArgs = Args> = StoryFn<StoryArgs<TArgs>>; | ||
|
||
/** | ||
* Combined Storybook story args. | ||
*/ | ||
export type StoryArgs<TArgs = Args> = Partial<Omit<TArgs, keyof FASTElement>> & Args; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const FluentDesignSystem = Object.freeze({ | ||
prefix: 'fluent', | ||
shadowRootMode: 'open', | ||
registry: customElements, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './index'; | ||
export * from './index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const empty = ''; | ||
export * from './text/index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { FluentDesignSystem } from '../fluent-design-system.js'; | ||
import { definition } from './text.definition.js'; | ||
|
||
definition.define(FluentDesignSystem.registry); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './text.js'; | ||
export * from './text.options.js'; | ||
export { template as TextTemplate } from './text.template.js'; | ||
export { styles as TextStyles } from './text.styles.js'; | ||
export { definition as TextDefinition } from './text.definition.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { FluentDesignSystem } from '../fluent-design-system.js'; | ||
import { Text } from './text.js'; | ||
import { styles } from './text.styles.js'; | ||
import { template } from './text.template.js'; | ||
|
||
/** | ||
* The Fluent Text Element. | ||
* | ||
* | ||
* @public | ||
* @remarks | ||
* HTML Element: \<fluent-text\> | ||
*/ | ||
export const definition = Text.compose({ | ||
name: `${FluentDesignSystem.prefix}-text`, | ||
template, | ||
styles, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { ValuesOf } from '@microsoft/fast-foundation'; | ||
|
||
/** | ||
* TextSize constants | ||
* @public | ||
*/ | ||
export const TextSize = { | ||
_100: '100', | ||
_200: '200', | ||
_300: '300', | ||
_400: '400', | ||
_500: '500', | ||
_600: '600', | ||
_700: '700', | ||
_800: '800', | ||
_900: '900', | ||
_1000: '1000', | ||
} as const; | ||
|
||
/** | ||
* The type for TextSize | ||
* The font size and line height based on the theme tokens | ||
* @public | ||
*/ | ||
export type TextSize = ValuesOf<typeof TextSize>; | ||
|
||
/** | ||
* TextFont Constants | ||
* @public | ||
*/ | ||
export const TextFont = { | ||
base: 'base', | ||
numeric: 'numeric', | ||
monospace: 'monospace', | ||
} as const; | ||
|
||
/** | ||
* Applies font family to the content | ||
* @public | ||
*/ | ||
export type TextFont = ValuesOf<typeof TextFont>; | ||
|
||
/** | ||
* TextWeight Constants | ||
* @public | ||
*/ | ||
export const TextWeight = { | ||
medium: 'medium', | ||
regular: 'regular', | ||
semibold: 'semibold', | ||
bold: 'bold', | ||
} as const; | ||
|
||
/** | ||
* Applies font weight to the content | ||
* @public | ||
*/ | ||
export type TextWeight = ValuesOf<typeof TextWeight>; | ||
|
||
/** | ||
* TextAlign Constants | ||
* @public | ||
*/ | ||
export const TextAlign = { | ||
start: 'start', | ||
end: 'end', | ||
center: 'center', | ||
justify: 'justify', | ||
} as const; | ||
|
||
/** | ||
* Aligns the content | ||
* @public | ||
*/ | ||
export type TextAlign = ValuesOf<typeof TextAlign>; |
Oops, something went wrong.