-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feature/custom button #625
base: feature/ant5
Are you sure you want to change the base?
Conversation
…rk with new versions
…um-website into feature/config-provider
…um-website into feature/ant5-styling
…simularium-website into feature/custom-button
interface CustomButtonProps extends Omit<AntButtonProps, "type" | "variant"> { | ||
variant?: ButtonClass; | ||
titleText?: string; | ||
icon?: ReactNode; | ||
onClick?: () => void; | ||
} | ||
|
||
interface TooltipText { | ||
defaultText: string; | ||
disabledText?: string; | ||
} | ||
|
||
interface TooltilButtonProps extends CustomButtonProps { | ||
tooltipText: TooltipText; | ||
tooltipPlacement?: TooltipPlacement; | ||
} |
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.
Currently the style rules, basic button, and button with tooltip are all here in the same file. I'm open to the argument that they be split up! But at this stage I like having it all in one place.
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.
Some minor comments but this approach is really elegant! LGTM!
import React from "react"; | ||
import { Link } from "react-router-dom"; | ||
import { Button, message, Upload, UploadProps } from "antd"; | ||
import { message, Upload, UploadProps } from "antd"; | ||
import { CloseOutlined } from "@ant-design/icons"; | ||
import { RcFile } from "antd/lib/upload"; | ||
|
||
import { ButtonClass } from "../../constants/interfaces"; | ||
import { VIEWER_PATHNAME } from "../../routes"; | ||
import { CustomButton } from "../CustomButton"; |
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.
This is making me think it might be nice to add an import sorting plugin to the repo...
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.
yes, I want that
button: { | ||
hoverBg: baseColors.transparent, | ||
activeBg: baseColors.transparent, | ||
primary: { | ||
light: { | ||
background: baseColors.dark.five, | ||
text: baseColors.gray.six, | ||
hover: { | ||
background: baseColors.dark.one, | ||
text: semanticColors.primaryPurple, | ||
}, | ||
active: { | ||
background: baseColors.dark.one, | ||
text: semanticColors.primaryPurple, | ||
}, | ||
focus: { | ||
outline: semanticColors.primaryPurple, | ||
}, | ||
disabled: { | ||
background: baseColors.purple.three, | ||
text: baseColors.gray.six, | ||
}, | ||
}, |
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'm a big fan of this nested structure! I should clean up TFE's theme type at some point.
disabledText?: string; | ||
} | ||
|
||
interface TooltilButtonProps extends CustomButtonProps { |
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.
interface TooltilButtonProps extends CustomButtonProps { | |
interface TooltipButtonProps extends CustomButtonProps { |
} | ||
|
||
&:active:not(:disabled) { | ||
background-color: ${hover.background}; |
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.
Nit: I feel like I'd expect this to be active.background
, though I can see why it would be redundant if none of the buttons change background between active and hover states.
const [tooltipRenderText, setTooltipRenderText] = useState( | ||
disabled ? tooltipText.disabledText : tooltipText.defaultText | ||
); |
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.
Does this need to be stateful? Is this to prevent the rendered text from changing while the tooltip is open?
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.
Hey good catch, no it doesn't. Also the tooltip behavior wasn't actually working with the new disabled prop so this comment helped me catch that!
Adding a wrapper div to handle the mouse events so disabled buttons still show tooltips, and making tooltipRenderText
a plain const
since the button always re renders!
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.
Smells reasonable to me!
Left some minor comments. Not sure I'm up to speed with the latest CSS technology.
--dark-theme-secondary-button-disabled-bg: transparent; | ||
--dark-theme-secondary-button-disabled-border: var(--dark-theme-header-bg); | ||
--dark-theme-secondary-button-disabled-color: var(--dim-gray-two); | ||
/* --dark-theme-primary-button-bg: var(--baby-purple); |
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.
Are lines 60 and 61 here still necessary?
@@ -42,8 +42,10 @@ export type TooltipPlacement = | |||
| "rightBottom"; | |||
|
|||
export enum ButtonClass { |
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.
Too lazy to check this myself - is this enum used anywhere beyond the CustomButton
component props? If not, would it be the right idea to just export it from CustomButton
? That's what I would do, but I don't typically make big constant files like these.
border: 1px solid ${variant === "primary" ? background : border}; | ||
color: ${text}; | ||
|
||
&&& { |
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.
Yeesh. Which brand of CSS magic does this triple ampersand belong to? Does this mean "parent-parent-parent"..?
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.
No! It's both better and worse than that.
In styled-components
this just directly raises the specificity of the current selector. Yes, this is arbitrary and smells a bit like using !important
but for me its a needed workaround for quality of life when styling antd
.
Because some antd
components apply many different class names, change element nesting, and even changes which base html element is rendered for different components, it can be tricky to ensure that our styles will be consistently applied. This solves that in a brute force kind of way, but is better than using !important
because these triple applied class hashes CAN be overridden by something of greater selector specificity, whereas !important
ignores the specificity hierarchy entirely.
When our styles don't really map onto ant's opinions very well, I prefer to just sort of veto all their styling by using this triple ampersand.
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.
Thanks, I sort of it get it now.
Does there come a point where we eschew the ant buttons altogether and just roll our own from scratch 🤔 ? I'd be curious as to when the team would consider that to be worth it.
This isn't a request for changes though! Feel free to resolve.
Time estimate or Size
small/medium
the final PR into the feature branch for this migration??
Problem
Button styling got messed up during
ant
migrationAlso our approach to styling buttons is a bit all over the place.
Solution
Replace
NavButton
with more generalCustomButton
, a styled-component.Delete:
NavButton
et. al, andlight-theme.css
and its directory.The light-theme file was a bit of an anachronism from auto-conversion work.
ButtonClass
Is expanded to cover all five of our basic button styled from the figma master guide (light and dark primary, light and dark secondary, and action buttons). Using the enum instead of raw strings is more type-safe and developer friendly.
Native antd
variant
prop is omitted and replaced with our own custom variants.CustomButton
As in the case of
DropdownMenuItems
,antd
can be a bit heavy handed with class names, and also swaps out underlying html in certain cases.Using a
styled-component
helps address specificity and consolidate the styling of buttons in one place.Other buttons in the app (
ViewportButton
andDropdownMenuItems
) are functionally and stylistically distinct, and either weren't much affected in migration or have already been addressed.