diff --git a/docs/data/components/no-ssr/FrameDeferring.js b/docs/data/components/no-ssr/FrameDeferring.js index 4a9b5b5f13..1b8358f88f 100644 --- a/docs/data/components/no-ssr/FrameDeferring.js +++ b/docs/data/components/no-ssr/FrameDeferring.js @@ -1,7 +1,7 @@ 'use client'; import * as React from 'react'; +import { styled } from '@mui/system'; import { NoSsr } from '@base_ui/react/NoSsr'; -import { Box } from '@mui/system'; function LargeTree() { return Array.from(new Array(5000)).map((_, index) => .); @@ -14,8 +14,8 @@ export default function FrameDeferring() { }); return ( -
- + {'Render '} +
- + {'Render '} +

- + {state.open ? (
Outside NoSsr
@@ -50,7 +50,38 @@ export default function FrameDeferring() {
) : null} - -
+ + ); } + +const Panel = styled('div')` + padding: 16px; +`; + +const Demo = styled('div')` + height: 250px; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: center; + overflow: auto; + padding: 8px; +`; + +const Button = styled('button')( + ({ theme }) => ` + background-color: ${theme.palette.mode === 'dark' ? 'var(--gray-50)' : 'var(--gray-900)'}; + color: ${theme.palette.mode === 'dark' ? 'var(--gray-900)' : 'var(--gray-50)'}; + padding: 8px 16px; + border-radius: 4px; + border: none; + font-family: + "IBM Plex Sans", + sans-serif; + + &:hover { + background-color: ${theme.palette.mode === 'dark' ? 'var(--gray-200)' : 'var(--gray-700)'}; + } +`, +); diff --git a/docs/data/components/no-ssr/FrameDeferring.tsx b/docs/data/components/no-ssr/FrameDeferring.tsx index 3b1679494c..dc1deed6db 100644 --- a/docs/data/components/no-ssr/FrameDeferring.tsx +++ b/docs/data/components/no-ssr/FrameDeferring.tsx @@ -1,7 +1,7 @@ 'use client'; import * as React from 'react'; +import { styled } from '@mui/system'; import { NoSsr } from '@base_ui/react/NoSsr'; -import { Box } from '@mui/system'; function LargeTree(): any { return Array.from(new Array(5000)).map((_, index) => .); @@ -14,8 +14,8 @@ export default function FrameDeferring() { }); return ( -
- + {'Render '} +
- + {'Render '} +

- + {state.open ? (
Outside NoSsr
@@ -50,7 +50,38 @@ export default function FrameDeferring() {
) : null} - -
+ + ); } + +const Panel = styled('div')` + padding: 16px; +`; + +const Demo = styled('div')` + height: 250px; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: center; + overflow: auto; + padding: 8px; +`; + +const Button = styled('button')( + ({ theme }) => ` + background-color: ${theme.palette.mode === 'dark' ? 'var(--gray-50)' : 'var(--gray-900)'}; + color: ${theme.palette.mode === 'dark' ? 'var(--gray-900)' : 'var(--gray-50)'}; + padding: 8px 16px; + border-radius: 4px; + border: none; + font-family: + "IBM Plex Sans", + sans-serif; + + &:hover { + background-color: ${theme.palette.mode === 'dark' ? 'var(--gray-200)' : 'var(--gray-700)'}; + } +`, +); diff --git a/docs/data/components/no-ssr/SimpleNoSsr.js b/docs/data/components/no-ssr/SimpleNoSsr.js index 4c3fa6b528..35f941d7a4 100644 --- a/docs/data/components/no-ssr/SimpleNoSsr.js +++ b/docs/data/components/no-ssr/SimpleNoSsr.js @@ -1,21 +1,31 @@ 'use client'; import * as React from 'react'; +import { styled } from '@mui/system'; import { NoSsr } from '@base_ui/react/NoSsr'; -import { Box } from '@mui/system'; export default function SimpleNoSsr() { return ( -
- - Server and Client - + + Server and Client - - Client only - + Client only -
+ ); } + +const Demo = styled('div')` + height: 250px; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + overflow: auto; + padding: 8px; +`; + +const Panel = styled('div')` + padding: var(--space-2); + margin-bottom: var(--space-1); + background-color: var(--gray-100); +`; diff --git a/docs/data/components/no-ssr/SimpleNoSsr.tsx b/docs/data/components/no-ssr/SimpleNoSsr.tsx index 4c3fa6b528..35f941d7a4 100644 --- a/docs/data/components/no-ssr/SimpleNoSsr.tsx +++ b/docs/data/components/no-ssr/SimpleNoSsr.tsx @@ -1,21 +1,31 @@ 'use client'; import * as React from 'react'; +import { styled } from '@mui/system'; import { NoSsr } from '@base_ui/react/NoSsr'; -import { Box } from '@mui/system'; export default function SimpleNoSsr() { return ( -
- - Server and Client - + + Server and Client - - Client only - + Client only -
+ ); } + +const Demo = styled('div')` + height: 250px; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + overflow: auto; + padding: 8px; +`; + +const Panel = styled('div')` + padding: var(--space-2); + margin-bottom: var(--space-1); + background-color: var(--gray-100); +`; diff --git a/docs/data/components/no-ssr/SimpleNoSsr.tsx.preview b/docs/data/components/no-ssr/SimpleNoSsr.tsx.preview index a8a7f332c0..68a53789b1 100644 --- a/docs/data/components/no-ssr/SimpleNoSsr.tsx.preview +++ b/docs/data/components/no-ssr/SimpleNoSsr.tsx.preview @@ -1,10 +1,6 @@ - - Server and Client - - - - Client only - - \ No newline at end of file + + Server and Client + + Client only + + \ No newline at end of file diff --git a/docs/data/components/no-ssr/no-ssr.mdx b/docs/data/components/no-ssr/no-ssr.mdx index 2b5d587c18..ccbda1f62a 100644 --- a/docs/data/components/no-ssr/no-ssr.mdx +++ b/docs/data/components/no-ssr/no-ssr.mdx @@ -1,6 +1,6 @@ --- productId: base-ui -title: No SSR React component +title: No-SSR React component description: The No-SSR component defers the rendering of children components from the server to the client. components: NoSsr --- diff --git a/docs/data/pages.ts b/docs/data/pages.ts index b82dc07f79..ad85e64f27 100644 --- a/docs/data/pages.ts +++ b/docs/data/pages.ts @@ -31,6 +31,7 @@ const pages: readonly RouteMetadata[] = [ { pathname: '/components/react-fieldset', title: 'Fieldset' }, { pathname: '/components/react-form', title: 'Form' }, { pathname: '/components/react-menu', title: 'Menu' }, + { pathname: '/components/react-no-ssr', title: 'No-SSR' }, { pathname: '/components/react-number-field', title: 'Number Field' }, { pathname: '/components/react-popover', title: 'Popover' }, { pathname: '/components/react-preview-card', title: 'Preview Card' }, diff --git a/docs/data/translations/api-docs/no-ssr/no-ssr.json b/docs/data/translations/api-docs/no-ssr/no-ssr.json index ff903d12a2..67843eefbf 100644 --- a/docs/data/translations/api-docs/no-ssr/no-ssr.json +++ b/docs/data/translations/api-docs/no-ssr/no-ssr.json @@ -1,7 +1,7 @@ { "componentDescription": "NoSsr purposely removes components from the subject of Server Side Rendering (SSR).\n\nThis component can be useful in a variety of situations:\n\n* Escape hatch for broken dependencies not supporting SSR.\n* Improve the time-to-first paint on the client by only rendering above the fold.\n* Reduce the rendering time on the server.\n* Under too heavy server load, you can turn on service degradation.", "propDescriptions": { - "children": { "description": "You can wrap a node." }, + "children": { "description": "React node to render on client only." }, "defer": { "description": "If true, the component will not only prevent server-side rendering. It will also defer the rendering of the children into a different screen frame." }, diff --git a/docs/src/components/demo/Demo.module.css b/docs/src/components/demo/Demo.module.css index a4910b833a..27395fe25f 100644 --- a/docs/src/components/demo/Demo.module.css +++ b/docs/src/components/demo/Demo.module.css @@ -9,8 +9,8 @@ flex-direction: column; align-items: center; justify-content: center; - padding-top: 64px; - padding-bottom: 64px; + min-height: 150px; + padding: var(--space-2); &:focus { box-shadow: 0 0 0 1px var(--gray-outline-2) inset; diff --git a/packages/mui-base/src/NoSsr/NoSsr.tsx b/packages/mui-base/src/NoSsr/NoSsr.tsx index 50e936efb3..62915dc488 100644 --- a/packages/mui-base/src/NoSsr/NoSsr.tsx +++ b/packages/mui-base/src/NoSsr/NoSsr.tsx @@ -2,7 +2,6 @@ import * as React from 'react'; import PropTypes from 'prop-types'; import { exactProp, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils'; -import { NoSsrProps } from './NoSsr.types'; /** * NoSsr purposely removes components from the subject of Server Side Rendering (SSR). @@ -22,7 +21,7 @@ import { NoSsrProps } from './NoSsr.types'; * * - [NoSsr API](https://base-ui.netlify.app/components/react-no-ssr/#api-reference-NoSsr) */ -function NoSsr(props: NoSsrProps): JSX.Element { +function NoSsr(props: NoSsr.Props): JSX.Element { const { children, defer = false, fallback = null } = props; const [mountedState, setMountedState] = React.useState(false); @@ -42,13 +41,33 @@ function NoSsr(props: NoSsrProps): JSX.Element { return {mountedState ? children : fallback}; } +namespace NoSsr { + export interface Props { + /** + * React node to render on client only. + */ + children?: React.ReactNode; + /** + * If `true`, the component will not only prevent server-side rendering. + * It will also defer the rendering of the children into a different screen frame. + * @default false + */ + defer?: boolean; + /** + * The fallback content to display. + * @default null + */ + fallback?: React.ReactNode; + } +} + NoSsr.propTypes /* remove-proptypes */ = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** - * You can wrap a node. + * React node to render on client only. */ children: PropTypes.node, /** diff --git a/packages/mui-base/src/NoSsr/NoSsr.types.ts b/packages/mui-base/src/NoSsr/NoSsr.types.ts deleted file mode 100644 index 1efd5c8771..0000000000 --- a/packages/mui-base/src/NoSsr/NoSsr.types.ts +++ /dev/null @@ -1,19 +0,0 @@ -import * as React from 'react'; - -export interface NoSsrProps { - /** - * You can wrap a node. - */ - children?: React.ReactNode; - /** - * If `true`, the component will not only prevent server-side rendering. - * It will also defer the rendering of the children into a different screen frame. - * @default false - */ - defer?: boolean; - /** - * The fallback content to display. - * @default null - */ - fallback?: React.ReactNode; -} diff --git a/packages/mui-base/src/NoSsr/index.ts b/packages/mui-base/src/NoSsr/index.ts index 546b249ab2..9d9d355e65 100644 --- a/packages/mui-base/src/NoSsr/index.ts +++ b/packages/mui-base/src/NoSsr/index.ts @@ -1,2 +1 @@ export { NoSsr } from './NoSsr'; -export * from './NoSsr.types'; diff --git a/packages/mui-base/src/index.ts b/packages/mui-base/src/index.ts index 9a3bda5f70..472ed9f058 100644 --- a/packages/mui-base/src/index.ts +++ b/packages/mui-base/src/index.ts @@ -3,6 +3,7 @@ export * from './Checkbox/index.barrel'; export * from './CheckboxGroup/index.barrel'; export * from './Dialog/index.barrel'; export * from './NumberField/index.barrel'; +export * from './NoSsr/index'; export * from './Popover/index.barrel'; export * from './Progress/index.barrel'; export * from './Slider/index.barrel';