Skip to content

Core: Revert Emotion :first-child (etc) workarounds #21213

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

Merged
merged 7 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions code/ui/blocks/src/components/ArgsTable/ArgsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { FC } from 'react';
import React from 'react';
import pickBy from 'lodash/pickBy.js';
import { styled } from '@storybook/theming';
import { transparentize } from 'polished';
import { styled, ignoreSsrWarning } from '@storybook/theming';
import { transparentize, darken, lighten } from 'polished';
import { includeConditionalArg } from '@storybook/csf';
import { once } from '@storybook/client-logger';
import { IconButton, Icons, Link, ResetWrapper } from '@storybook/components';
Expand Down Expand Up @@ -107,6 +107,24 @@ export const TableWrapper = styled.table<{
marginLeft: inAddonPanel ? 0 : 1,
marginRight: inAddonPanel ? 0 : 1,

[`tr:first-child${ignoreSsrWarning}`]: {
[`td:first-child${ignoreSsrWarning}, th:first-child${ignoreSsrWarning}`]: {
borderTopLeftRadius: inAddonPanel ? 0 : theme.appBorderRadius,
},
[`td:last-child${ignoreSsrWarning}, th:last-child${ignoreSsrWarning}`]: {
borderTopRightRadius: inAddonPanel ? 0 : theme.appBorderRadius,
},
},

[`tr:last-child${ignoreSsrWarning}`]: {
[`td:first-child${ignoreSsrWarning}, th:first-child${ignoreSsrWarning}`]: {
borderBottomLeftRadius: inAddonPanel ? 0 : theme.appBorderRadius,
},
[`td:last-child${ignoreSsrWarning}, th:last-child${ignoreSsrWarning}`]: {
borderBottomRightRadius: inAddonPanel ? 0 : theme.appBorderRadius,
},
},

tbody: {
// Safari doesn't love shadows on tbody so we need to use a shadow filter. In order to do this,
// the table cells all need to be solid so they have a background color applied.
Expand All @@ -121,8 +139,31 @@ export const TableWrapper = styled.table<{
: `drop-shadow(0px 1px 3px rgba(0, 0, 0, 0.20))`,
}),

'> tr > *': {
// For filter to work properly, the table cells all need to be opaque.
tr: {
background: 'transparent',
overflow: 'hidden',
...(inAddonPanel
? {
borderTopWidth: 1,
borderTopStyle: 'solid',
borderTopColor:
theme.base === 'light'
? darken(0.1, theme.background.content)
: lighten(0.05, theme.background.content),
}
: {
[`&:not(:first-child)${ignoreSsrWarning}`]: {
borderTopWidth: 1,
borderTopStyle: 'solid',
borderTopColor:
theme.base === 'light'
? darken(0.1, theme.background.content)
: lighten(0.05, theme.background.content),
},
}),
},

td: {
background: theme.background.content,
borderTop: `1px solid ${theme.appBorderColor}`,
},
Expand Down
4 changes: 2 additions & 2 deletions code/ui/blocks/src/components/Source.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ComponentProps, FunctionComponent } from 'react';
import React from 'react';
import { styled, ThemeProvider, convert, themes } from '@storybook/theming';
import { styled, ThemeProvider, convert, themes, ignoreSsrWarning } from '@storybook/theming';
import { SyntaxHighlighter } from '@storybook/components';

import { EmptyBlock } from './EmptyBlock';
Expand Down Expand Up @@ -69,7 +69,7 @@ const SourceSkeletonPlaceholder = styled.div(({ theme }) => ({
marginTop: 1,
width: '60%',

[`&:first-child`]: {
[`&:first-child${ignoreSsrWarning}`]: {
margin: 0,
},
}));
Expand Down
6 changes: 3 additions & 3 deletions code/ui/components/src/spaced/Spaced.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FC } from 'react';
import React from 'react';
import { styled } from '@storybook/theming';
import { styled, ignoreSsrWarning } from '@storybook/theming';

const toNumber = (input: any) => (typeof input === 'number' ? input : Number(input));

Expand All @@ -20,15 +20,15 @@ const Container = styled.div<ContainerProps>(
marginLeft: col * theme.layoutMargin,
verticalAlign: 'inherit',
},
[`& > *:first-child`]: {
[`& > *:first-child${ignoreSsrWarning}`]: {
marginLeft: 0,
},
}
: {
'& > *': {
marginTop: row * theme.layoutMargin,
},
[`& > *:first-child`]: {
[`& > *:first-child${ignoreSsrWarning}`]: {
marginTop: 0,
},
},
Expand Down
5 changes: 4 additions & 1 deletion code/ui/components/src/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import type { ChildrenList } from './tabs.helpers';
import { childrenToList, VisuallyHidden } from './tabs.helpers';
import { useList } from './tabs.hooks';

const ignoreSsrWarning =
'/* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */';

export interface WrapperProps {
bordered?: boolean;
absolute?: boolean;
Expand Down Expand Up @@ -84,7 +87,7 @@ const Content = styled.div<ContentProps>(
bottom: 0 + (bordered ? 1 : 0),
top: 40 + (bordered ? 1 : 0),
overflow: 'auto',
[`& > *:first-child`]: {
[`& > *:first-child${ignoreSsrWarning}`]: {
position: 'absolute',
left: 0 + (bordered ? 1 : 0),
right: 0 + (bordered ? 1 : 0),
Expand Down
29 changes: 10 additions & 19 deletions code/ui/manager/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@ import ReactDOM from 'react-dom';
import { Location, LocationProvider, useNavigate } from '@storybook/router';
import { Provider as ManagerProvider } from '@storybook/manager-api';
import type { Combo } from '@storybook/manager-api';
import {
ThemeProvider,
ensure as ensureTheme,
CacheProvider,
createCache,
} from '@storybook/theming';
import { ThemeProvider, ensure as ensureTheme } from '@storybook/theming';

import { HelmetProvider } from 'react-helmet-async';

import App from './app';

import Provider from './provider';

const emotionCache = createCache({ key: 'sto' });
emotionCache.compat = true;

// @ts-expect-error (Converted from ts-ignore)
ThemeProvider.displayName = 'ThemeProvider';
// @ts-expect-error (Converted from ts-ignore)
Expand Down Expand Up @@ -59,16 +52,14 @@ const Main: FC<{ provider: Provider }> = ({ provider }) => {
: !state.previewInitialized;

return (
<CacheProvider value={emotionCache}>
<ThemeProvider key="theme.provider" theme={ensureTheme(state.theme)}>
<App
key="app"
viewMode={state.viewMode}
layout={isLoading ? { ...state.layout, showPanel: false } : state.layout}
panelCount={panelCount}
/>
</ThemeProvider>
</CacheProvider>
<ThemeProvider key="theme.provider" theme={ensureTheme(state.theme)}>
<App
key="app"
viewMode={state.viewMode}
layout={isLoading ? { ...state.layout, showPanel: false } : state.layout}
panelCount={panelCount}
/>
</ThemeProvider>
);
}}
</ManagerProvider>
Expand Down