Skip to content

Commit

Permalink
fix: component style without hash (#46609)
Browse files Browse the repository at this point in the history
* fix: Select style without hash

* fix: common style logic

* fix: lint

* fix: menu style

* chore: update checkbox demo

* chore: fix test

* chore: rm test
  • Loading branch information
MadCcc committed Jan 30, 2024
1 parent c61870e commit 441ba5f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 30 deletions.
1 change: 1 addition & 0 deletions .dumi/theme/layouts/GlobalLayout.tsx
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
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
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
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
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
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
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

0 comments on commit 441ba5f

Please sign in to comment.