-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
feat: add text as new component #26090
Merged
chrisdholt
merged 8 commits into
microsoft:web-components-v3
from
chrisdholt:users/chhol/add-text-as-new-component
Jan 12, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2b59bcc
add text as a new component
chrisdholt 7e6d618
update main.js to .cjs format for esm due to require syntax
chrisdholt 935ce00
update style rules to align with FUI react v9, export text options, u…
chrisdholt 7fc847c
export text, update node resolution to 16 and fix object.keys for siz…
chrisdholt 25d0878
prettier style files, may need to revert if it does not play nice wit…
chrisdholt a157fe4
update display for host to ensure we can layout the element properly …
chrisdholt 4a20b5a
update latest FAST packages
chrisdholt 18ec7f8
leverage ValuesOf type helper
chrisdholt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = { | ||
chrisdholt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_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; | ||
chrisdholt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I do not understand why the component definition is coupled with
FluentDesignSystem.prefix
.We pass
registry
todefinition.define()
to support custom/multiple registries. In that case, wouldn't it make sense to pass the prefix todefine()
as well?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.
Good question - Let me follow up on this. If you can send a mail I'll take it offline. This was a pattern we established awhile ago and I want to make sure I'm not missing something w/r/t our discussion around "defaultRegistry" vs current implementation.