-
Notifications
You must be signed in to change notification settings - Fork 902
fix(site): disable auto fields when they are disabled in the template settings #10022
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { type FC, type ReactNode, useMemo } from "react"; | ||
import { type FC, type ReactNode, useMemo, forwardRef } from "react"; | ||
import { css, type Interpolation, type Theme, useTheme } from "@emotion/react"; | ||
import { colors } from "theme/colors"; | ||
|
||
|
@@ -44,61 +44,71 @@ const themeStyles = | |
}; | ||
}; | ||
|
||
export const Pill: FC<PillProps> = (props) => { | ||
const { lightBorder, icon, text = null, type = "neutral", ...attrs } = props; | ||
const theme = useTheme(); | ||
export const Pill: FC<PillProps> = forwardRef<HTMLDivElement, PillProps>( | ||
(props, ref) => { | ||
const { | ||
lightBorder, | ||
icon, | ||
text = null, | ||
type = "neutral", | ||
...attrs | ||
} = props; | ||
const theme = useTheme(); | ||
|
||
const typeStyles = useMemo(() => { | ||
if (type in themeOverrides) { | ||
return themeOverrides[type as keyof typeof themeOverrides](lightBorder); | ||
} | ||
return themeStyles(type, lightBorder); | ||
}, [type, lightBorder]); | ||
const typeStyles = useMemo(() => { | ||
if (type in themeOverrides) { | ||
return themeOverrides[type as keyof typeof themeOverrides](lightBorder); | ||
} | ||
return themeStyles(type, lightBorder); | ||
}, [type, lightBorder]); | ||
|
||
return ( | ||
<div | ||
css={[ | ||
{ | ||
display: "inline-flex", | ||
alignItems: "center", | ||
borderWidth: 1, | ||
borderStyle: "solid", | ||
borderRadius: 99999, | ||
fontSize: 12, | ||
color: "#FFF", | ||
height: theme.spacing(3), | ||
paddingLeft: icon ? theme.spacing(0.75) : theme.spacing(1.5), | ||
paddingRight: theme.spacing(1.5), | ||
whiteSpace: "nowrap", | ||
fontWeight: 400, | ||
}, | ||
typeStyles, | ||
]} | ||
role="status" | ||
{...attrs} | ||
> | ||
{icon && ( | ||
<div | ||
css={css` | ||
margin-right: ${theme.spacing(0.5)}; | ||
width: ${theme.spacing(1.75)}; | ||
height: ${theme.spacing(1.75)}; | ||
line-height: 0; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
& > img, | ||
& > svg { | ||
return ( | ||
<div | ||
ref={ref} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am probably missing something obvious, but what does passing in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ref gives any parent component the ability to manipulate the the div element created by Pill. So for example: function Parent () {
const divRef = useRef<HTMLDivElement>(null);
return <Pill ref={divRef} {...otherProps} />
} With this setup, the parent would be able to manipulate the real HTML div element that Pill creates from inside useEffect and event handlers, even though the div exists in a separate component There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But judging from this PR, I think it's a preemptive change to make the component more reusable. I don't see any of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is used by the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohhhhh I see. I see it in the docs. Unfortunate that it is not reflected in the code! I guess you just have to know how MUI tooltip works. Thanks for the explanations! |
||
css={[ | ||
{ | ||
cursor: "default", | ||
display: "inline-flex", | ||
alignItems: "center", | ||
borderWidth: 1, | ||
borderStyle: "solid", | ||
borderRadius: 99999, | ||
fontSize: 12, | ||
color: "#FFF", | ||
height: theme.spacing(3), | ||
paddingLeft: icon ? theme.spacing(0.75) : theme.spacing(1.5), | ||
paddingRight: theme.spacing(1.5), | ||
whiteSpace: "nowrap", | ||
fontWeight: 400, | ||
}, | ||
typeStyles, | ||
]} | ||
role="status" | ||
{...attrs} | ||
> | ||
{icon && ( | ||
<div | ||
css={css` | ||
margin-right: ${theme.spacing(0.5)}; | ||
width: ${theme.spacing(1.75)}; | ||
height: ${theme.spacing(1.75)}; | ||
} | ||
`} | ||
> | ||
{icon} | ||
</div> | ||
)} | ||
{text} | ||
</div> | ||
); | ||
}; | ||
line-height: 0; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
& > img, | ||
& > svg { | ||
width: ${theme.spacing(1.75)}; | ||
height: ${theme.spacing(1.75)}; | ||
} | ||
`} | ||
> | ||
{icon} | ||
</div> | ||
)} | ||
{text} | ||
</div> | ||
); | ||
}, | ||
); |
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 memoized? I guess it just feels like the logic wouldn't have much overhead, and it's only being used within the same component
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 don't think so, I guess it is only using
memo
as a way to wrap/encapsulate it into a function but I'm just guessing.