Skip to content

feat(react-spinbutton): Adding optional shadows to filled variants#24804

Closed
sopranopillow wants to merge 3 commits into
microsoft:masterfrom
sopranopillow:input/add-shadows-spinbutton
Closed

feat(react-spinbutton): Adding optional shadows to filled variants#24804
sopranopillow wants to merge 3 commits into
microsoft:masterfrom
sopranopillow:input/add-shadows-spinbutton

Conversation

@sopranopillow

Copy link
Copy Markdown
Contributor

image

Related Issue(s)

Fixes #24642

@fabricteam

fabricteam commented Sep 15, 2022

Copy link
Copy Markdown
Collaborator

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-spinbutton
SpinButton
44.102 kB
12.425 kB
44.309 kB
12.467 kB
207 B
42 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
188.672 kB
52.359 kB
react-components
react-components: FluentProvider & webLightTheme
33.394 kB
11.007 kB
react-portal-compat
PortalCompatProvider
5.851 kB
1.964 kB
🤖 This report was generated against 066df30538d0e73160db5b1739eaa2c101c0bc7c

@codesandbox-ci

codesandbox-ci Bot commented Sep 15, 2022

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9a28ce7:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

@size-auditor

size-auditor Bot commented Sep 15, 2022

Copy link
Copy Markdown

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: 066df30538d0e73160db5b1739eaa2c101c0bc7c (build)

@fabricteam

fabricteam commented Sep 15, 2022

Copy link
Copy Markdown
Collaborator

Perf Analysis (@fluentui/react-components)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 1279 1272 5000
Button mount 920 918 5000
FluentProvider mount 1495 1485 5000
FluentProviderWithTheme mount 577 592 10
FluentProviderWithTheme virtual-rerender 533 551 10
FluentProviderWithTheme virtual-rerender-with-unmount 573 576 10
MakeStyles mount 1925 1944 50000
SpinButton mount 2320 2342 5000

},
});

let buttonClassName: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This feels a bit heavy and I wonder if we couldn't simplify it a bit with something like:

// This is defined in the root of the module since it will never change
const appearanceMap: Record<string, string> = {
   outline: 'outline',
   //....
   'filled-lighter-shadow': 'filled-lighter',
   'filled-darker-shadow': 'filled-darker'
} as const;

// In useStyles where the classnames are merged
buttonStyles[appearanceMap[appearance]];

This would eliminate all the conditionals and make appearance styling more declarative, be less code overall (smaller bundle) and is probably faster to execute since it's just a lookup rather than several if...elses.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not sure if this is an issue, but it would end up looking like this due to the type Record<string,string>

buttonStyles[appearanceMap[appearance] as keyof typeof buttonStyles]

buttonActive: 'fui-SpinButton__button_active',
};

const appearanceMap: Record<string, string> = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can type this as the following to avoid the casts below

Suggested change
const appearanceMap: Record<string, string> = {
const appearanceMap: Record<string, keyof typeof buttonStyles> = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe even?

const appearanceMap: Record<SpinButtonProps['appearance'], keyof typeof buttonStyles> = {

@sopranopillow sopranopillow Sep 15, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we can't since we have these cases:

buttonDisabledStyles[appearanceMap[appearance] as keyof typeof buttonDisabledStyles]
buttonStyles[appearanceMap[appearance] as keyof typeof buttonStyles]

and I would need to create the variable buttonStyles in the root module.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The other thing you could do is move this object's creation within the useSpinButtonStyles_unstable function after the creation of buttonStyles (maybe around line 405). Then you could type it as I said in the comment above and remove the casts. If you don't want the object to be generated on every render you can use useMemo with an empty array as the dependency list

const appearanceMap: Record<SpinButtonProps['appearance'], keyof typeof buttonStyles> = React.useMemo(() => ({
  outline: 'outline',
  underline: 'underline',
  'filled-darker': 'filled-darker',
  'filled-lighter': 'filled-lighter',
  'filled-darker-shadow': 'filled-darker',
  'filled-lighter-shadow': 'filled-lighter',
}), [])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inputs: Add optional shadows to each component

5 participants