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(icon): convert icon slots to ShorthandValue<BoxProps> #12489

Merged
merged 73 commits into from
Apr 6, 2020

Conversation

mnajdova
Copy link
Contributor

@mnajdova mnajdova commented Mar 31, 2020

This PR changes all icon slots inside @fluentui/react-northstar to be shorthands of Box. All icon shorthands are replaced with icon components from the @fluentui/react-icons-northstar package.

This PR will not remove the Icon comeponent and will not change the Icon docs. Those will be implemented in follow up PRs.

There are few broken screeners mainly because of font -> svg icon changes

TODOs:

  • add changelog entry
  • fix icon usages in broken screener tests

BREAKING CHANGES

The icon prop in the following components was changed from ShorthandValue<IconProps> to ShorthandValue<BoxProps>:

  • Attachment
  • Button
  • DropdownSelectedItem
  • Input
  • Label
  • MenuItem
  • Reaction
  • Status
  • ToolbarItem
  • ToolbarMenuItem

The conversion looks like this:

<Button icon={{name: 'circle', outline: true }} /> => <Button icon={<CircleIcon />} />

Codemods prepared for the migration: https://github.com/joschect/ts-morphin-migration/tree/iconbranch

Note:
The codemods works only known component icon props, where the value string or object literal on the components.

Steps for migration:

  1. Change open icon jsx tags to self closing: <Icon ..></Icon> => <Icon ... />
  2. Run the codemods
  3. There will be more occurences for cases where some prop/objects are used and spreaded across components. Here are few useful searches that can be used for catching these (with Match case & Regexp):

icon=\{[^<]

icon: \{

icon: "(\w+)"
icon: "(\w+)-(\w+)"
icon: "(\w+)-(\w+)-(\w+)"

<Icon.*name

mnajdova and others added 30 commits March 27, 2020 12:02
-updated button props and examples
-fixed inconsistencies
…ents-test.tsx

Co-Authored-By: Oleksandr Fediashov <alexander.mcgarret@gmail.com>
…ents-test.tsx

Co-Authored-By: Oleksandr Fediashov <alexander.mcgarret@gmail.com>
…ents-test.tsx

Co-Authored-By: Oleksandr Fediashov <alexander.mcgarret@gmail.com>
@@ -92,7 +92,8 @@ class DropdownSelectedItem extends UIComponent<WithAsProp<DropdownSelectedItemPr
};

static defaultProps = {
icon: 'close',
// TODO: fix me
icon: <CloseIcon />,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be fixed in a follow up PR to avoid unrelated changes

@mnajdova mnajdova changed the title [WIP] feat(icon): convert icon slots to ShorthandValue<BoxProps> feat(icon): convert icon slots to ShorthandValue<BoxProps> Apr 3, 2020
@@ -69,7 +69,7 @@ const ComponentControls: React.FC<ComponentControlsProps> = props => {
aria-label={toolbarAriaLabel || null}
items={[
{
icon: { name: 'code', style: { width: '20px', height: '20px' } },
icon: <Icon name={'code'} {...{ style: { width: '20px', height: '20px' } }} />,
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to actually use spread for style instead of direct using the prop/attribute?

icon: <Icon name="code" style={{ width: '20px', height: '20px' }} />,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was auto generated by the codemods, which basically remove the name prop and spread the rest of the object on the component.

<Button
as={Link}
content={next.name}
icon={<Icon name="arrow right" />}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be <ArrowRightIcon /> ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a font icon, we don't have mapping for an svg icon

Copy link
Contributor

Choose a reason for hiding this comment

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

You mean when using icon in the button is font Icon or the arrow left itself? I got confused because PopupExamplePointing.shorthand.tsx it was using <ArrowRightIcon />

Copy link
Contributor Author

@mnajdova mnajdova Apr 3, 2020

Choose a reason for hiding this comment

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

It is a bit confusion yeah. Basically name="arrow-left" can be transform to <ArrowLeftIcon />, but here the name is arrow left which is a different font icon. Anyway, as it is not in an example we can change it to <ArrowRightIcon />, but my point was that it is a different icon.

@@ -447,7 +448,8 @@ class Toolbar extends UIComponent<WithAsProp<ToolbarProps>> {
<Ref innerRef={this.overflowItemRef}>
{ToolbarItem.create(overflowItem, {
defaultProps: () => ({
icon: { name: 'more', outline: true },
// TODO: ups
icon: <MoreIcon {...{ outline: true }} />,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be fixed after these changes are merged

styles: resolvedStyles.icon,
xSpacing: 'none',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is default no need for overriding styles

@@ -105,12 +104,6 @@ const Label: React.FC<WithAsProp<LabelProps>> & FluentComponentStaticProps = pro
rtl: context.rtl,
});

const handleIconOverrides = (predefinedProps: IconProps) => ({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need for this as xSpacing: undefined == 'none' is default

const { clearable, icon } = this.props;
const { value } = this.state;

if (clearable && (value as string).length !== 0) {
return { name: '' };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeey

defaultProps: () =>
getA11Props('icon', {
styles: resolvedStyles.icon,
xSpacing: !content ? 'none' : iconPosition === 'after' ? 'before' : 'after',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to styles

# Conflicts:
#	packages/fluentui/react-northstar/src/components/Alert/Alert.tsx
mnajdova and others added 2 commits April 3, 2020 17:06
…eFactoryMock.tsx

Co-Authored-By: Roman Sudarikov <pompomon@users.noreply.github.com>
…eFactoryMock.tsx

Co-Authored-By: Roman Sudarikov <pompomon@users.noreply.github.com>
@mnajdova mnajdova merged commit 908444b into microsoft:master Apr 6, 2020
DuanShaolong pushed a commit to DuanShaolong/fluentui that referenced this pull request Apr 27, 2020
…#12489)

* wip

* -fixed imports

* -added icons

* -reverted unintended changes

* -reverted unintended changes

* -reverted unintended changes

* -reverted unintended changes

* -fixed imports

* -added redPath

* -updated icon prop to box shorthand
-updated button props and examples

* -fixed jest config

* -fixed references

* -added components tests
-fixed inconsistencies

* -ts-morphin experiments

* -perf experiments

* -perf experiments

* Update packages/fluentui/react-icons-northstar/test/components/components-test.tsx

Co-Authored-By: Oleksandr Fediashov <alexander.mcgarret@gmail.com>

* Update packages/fluentui/react-icons-northstar/test/components/components-test.tsx

Co-Authored-By: Oleksandr Fediashov <alexander.mcgarret@gmail.com>

* Update packages/fluentui/react-icons-northstar/test/components/components-test.tsx

Co-Authored-By: Oleksandr Fediashov <alexander.mcgarret@gmail.com>

* -added packages

* -fixed tests

* -added Icon suffix

* -reverted perf test changes

* -removed author from package.json

* -changed some icon names to reflect the previous names
-added Icon suffix in name test

* -removed comments

* -fixed names

* ts-morphin changes

* -more ts-morphin changes

* -more ts-morphin changes

* -updated styles

* -updated menuItemStyles

* -fixed renderConfig

* -more ts morphin changes

* -more ts morphin changes (collection components)

* -added as: 'span' in MenuItem

* -more changes f+r

* -more changes ts-morphin

* -more changes ts-morphin

* -more changes ts-morphin

* -more changes ts-morphin

* -more changes ts-morphin

* -fixes

* -more changes f & r

* -more changes f & r

* -more changes f & r

* -more changes f & r

* -more changes f & r

* -fixes in status styles

* -fixes in components still dependent on icons

* -fixes

* -fixes

* -fixed some styles

* -fixed some styles and examples

* -test button styles

* -added variables

* -added variables

* -fixed toolbar menu item icon spacing

* -removed comment

* -fixed tests

* Update packages/fluentui/docs/src/prototypes/chatPane/services/messageFactoryMock.tsx

Co-Authored-By: Roman Sudarikov <pompomon@users.noreply.github.com>

* Update packages/fluentui/docs/src/prototypes/chatPane/services/messageFactoryMock.tsx

Co-Authored-By: Roman Sudarikov <pompomon@users.noreply.github.com>

* -final fixes

* -fixed tests

* -fixed tests

Co-authored-by: Oleksandr Fediashov <alexander.mcgarret@gmail.com>
Co-authored-by: Roman Sudarikov <pompomon@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fluent UI react-northstar (v0) Work related to Fluent UI V0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants