Skip to content
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 Toolbar component to teams-components #311

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ling1726
Copy link
Member

No description provided.

},
ref
);
useDividerStyles_unstable(state);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would double check if we really want to reuse Divider there

Comment on lines +1 to +5
export * from './Toolbar';
export * from './ToolbarDivider';
export * from './ToolbarButton';
export * from './ToolbarToggleButton';
export * from './ToolbarMenuButton';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too wild, let's be explicit

Comment on lines +6 to +7
private _treeWalker: TreeWalker;
private _filter: ElementFilter;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private _treeWalker: TreeWalker;
private _filter: ElementFilter;
#treeWalker: TreeWalker;
#filter: ElementFilter;

let's be cool

Comment on lines 123 to 141
const validateToolbarItems = (root: HTMLElement) => {
const children = root.children;
for (const child of children) {
// TODO is this even possible?
if (!isHTMLElement(child)) {
continue;
}

if (
!isAllowedToolbarItem(child) &&
!isPortalSpan(child) &&
!isTabsterDummy(child)
) {
throw new Error(
'@fluentui-contrib/teams-components::Toolbar::Use Toolbar components from @fluentui-contrib/teams-components package only'
);
}
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will definitely need a nicer validator

Comment on lines 61 to 67
const treeWalker = new HTMLElementWalker(elRef.current, (el) => {
if (isAllowedToolbarItem(el) || el === treeWalker.root) {
return NodeFilter.FILTER_ACCEPT;
}

return NodeFilter.FILTER_REJECT;
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TreeWalker is nice, but why? element.children with a filter will do the same

Comment on lines 164 to 165
if (prev && el.dataset.appearance !== 'transparent') {
prev.style.marginInlineStart = tokens.spacingHorizontalS;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to say, that this should be somehow declarative as it will go will quite quickly.

Dumb idea:

const STYLE_SCHEMAS = {
  kind: 'ToolbarButton',
  prevKind: 'ToolbarDivider',
  nextKind: null,
  meta: { appearance },
  style: { marginInlineStart: tokens.spacingHorizontalS },
}

function applyStylesToElement() {}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline - will try out registerProperty API without inheritable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could try leverage default react context or other means to make sure the cost of property registration only happens with usage


export const useItemRegistration = (metadata: ToolbarItemMetadata) => {
const { registerItem } = React.useContext(ToolbarItemRegistrationContext);
const styles = useItemRegistrationStyles();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about mixing styles there

Comment on lines +7 to +10
let propertyRegisterComplete = false;

export const registerCustomProperties = (win: typeof globalThis) => {
if (propertyRegisterComplete) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be done per window?

const styles = useItemRegistrationStyles();
const ref = React.useCallback((el: HTMLElement) => {
if (el) {
registerItem(el, metadata);
Copy link
Member

@layershifter layershifter Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't react on meta updates. Considering that it's an object, might be tricky

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants