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

fix: component style without hash #46609

Merged
merged 7 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .dumi/theme/layouts/GlobalLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ const GlobalLayout: React.FC = () => {
motion: !theme.includes('motion-off'),
},
cssVar: true,
hashed: false,
}}
>
<HappyProvider disabled={!theme.includes('happy-work')}>{content}</HappyProvider>
Expand Down
1 change: 0 additions & 1 deletion components/checkbox/demo/custom-line-width.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const App: React.FC = () => (
<>
<ConfigProvider
theme={{
cssVar: false,
components: {
Checkbox: {
lineWidth: 6,
Expand Down
2 changes: 1 addition & 1 deletion components/config-provider/__tests__/button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('ConfigProvider.button', () => {

it('ConfigProvider button styles', () => {
const { container } = render(
<ConfigProvider button={{ styles: { icon: { color: '#333' } } }}>
<ConfigProvider button={{ styles: { icon: { fontSize: 14 } } }}>
<Button icon={<SearchOutlined />} />
</ConfigProvider>,
);
Expand Down
30 changes: 15 additions & 15 deletions components/menu/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,21 @@ const getBaseStyle: GenerateStyle<MenuToken> = (token) => {
opacity: 0,
content: '""',
},

[`> ${componentCls}`]: {
borderRadius: borderRadiusLG,

...genMenuItemStyle(token),
...genSubMenuArrowStyle(token),

[`${componentCls}-item, ${componentCls}-submenu > ${componentCls}-submenu-title`]: {
borderRadius: subMenuItemBorderRadius,
},

[`${componentCls}-submenu-title::after`]: {
transition: `transform ${motionDurationSlow} ${motionEaseInOut}`,
},
},
},

// https://github.com/ant-design/ant-design/issues/13955
Expand Down Expand Up @@ -750,21 +765,6 @@ const getBaseStyle: GenerateStyle<MenuToken> = (token) => {
`]: {
paddingTop: token.paddingXS,
},

[`> ${componentCls}`]: {
borderRadius: borderRadiusLG,

...genMenuItemStyle(token),
...genSubMenuArrowStyle(token),

[`${componentCls}-item, ${componentCls}-submenu > ${componentCls}-submenu-title`]: {
borderRadius: subMenuItemBorderRadius,
},

[`${componentCls}-submenu-title::after`]: {
transition: `transform ${motionDurationSlow} ${motionEaseInOut}`,
},
},
},

...genSubMenuArrowStyle(token),
Expand Down
13 changes: 7 additions & 6 deletions components/menu/style/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ const getThemeStyle = (token: MenuToken, themeSuffix: string): CSSInterpolation
},
},

[`${componentCls}-item, ${componentCls}-submenu-title`]: {
color: itemColor,
[`&:not(${componentCls}-item-disabled):focus-visible`]: {
...accessibilityFocus(token),
},
},

// Disabled
[`${componentCls}-item-disabled, ${componentCls}-submenu-disabled`]: {
color: `${itemDisabledColor} !important`,
Expand Down Expand Up @@ -149,12 +156,6 @@ const getThemeStyle = (token: MenuToken, themeSuffix: string): CSSInterpolation
},
},

[`${componentCls}-item, ${componentCls}-submenu-title`]: {
[`&:not(${componentCls}-item-disabled):focus-visible`]: {
...accessibilityFocus(token),
},
},

[`&${componentCls}-submenu > ${componentCls}`]: {
backgroundColor: menuSubMenuBg,
},
Expand Down
11 changes: 8 additions & 3 deletions components/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,15 @@ export const genLinkStyle = (token: DerivativeToken): CSSObject => ({
},
});

export const genCommonStyle = (token: DerivativeToken, componentPrefixCls: string): CSSObject => {
export const genCommonStyle = (
token: DerivativeToken,
componentPrefixCls: string,
rootCls?: string,
): CSSObject => {
const { fontFamily, fontSize } = token;

const rootPrefixSelector = `[class^="${componentPrefixCls}"], [class*=" ${componentPrefixCls}"]`;
const prefixSelector = `[class^="${componentPrefixCls}"], [class*=" ${componentPrefixCls}"]`;
const rootPrefixSelector = rootCls ? `.${rootCls}` : prefixSelector;

return {
[rootPrefixSelector]: {
Expand All @@ -117,7 +122,7 @@ export const genCommonStyle = (token: DerivativeToken, componentPrefixCls: strin
boxSizing: 'border-box',
},

[rootPrefixSelector]: {
[prefixSelector]: {
boxSizing: 'border-box',

'&::before, &::after': {
Expand Down
10 changes: 6 additions & 4 deletions components/theme/util/genComponentStyleHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default function genComponentStyleHook<C extends OverrideComponent>(
const [component] = cells;
const concatComponent = cells.join('-');

return (prefixCls: string): UseComponentStyleResult => {
return (prefixCls: string, rootCls: string = prefixCls): UseComponentStyleResult => {
const [theme, realToken, hashId, token, cssVar] = useToken();
const { getPrefixCls, iconPrefixCls, csp } = useContext(ConfigContext);
const rootPrefixCls = getPrefixCls();
Expand Down Expand Up @@ -241,7 +241,7 @@ export default function genComponentStyleHook<C extends OverrideComponent>(
});
flush(component, componentToken);
return [
options.resetStyle === false ? null : genCommonStyle(mergedToken, prefixCls),
options.resetStyle === false ? null : genCommonStyle(mergedToken, prefixCls, rootCls),
styleInterpolation,
];
},
Expand All @@ -253,6 +253,7 @@ export default function genComponentStyleHook<C extends OverrideComponent>(

export interface SubStyleComponentProps {
prefixCls: string;
rootCls?: string;
}

// Get from second argument
Expand All @@ -272,8 +273,9 @@ export const genSubStyleComponent: <C extends OverrideComponent>(

const StyledComponent: ComponentType<SubStyleComponentProps> = ({
prefixCls,
rootCls = prefixCls,
}: SubStyleComponentProps) => {
useStyle(prefixCls);
useStyle(prefixCls, rootCls);
return null;
};

Expand Down Expand Up @@ -406,7 +408,7 @@ export const genStyleHooks = <C extends OverrideComponent>(
);

return (prefixCls: string, rootCls: string = prefixCls) => {
const [, hashId] = useStyle(prefixCls);
const [, hashId] = useStyle(prefixCls, rootCls);
const [wrapCSSVar, cssVarCls] = useCSSVar(rootCls);

return [wrapCSSVar, hashId, cssVarCls] as const;
Expand Down