Skip to content

Commit

Permalink
docs(Responsive): clarify SSR usage (#3373)
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter authored Jan 10, 2019
1 parent 01e2395 commit d53b354
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
18 changes: 18 additions & 0 deletions docs/src/examples/addons/Responsive/Usage/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import React from 'react'
import { Button, Message, Segment } from 'semantic-ui-react'

import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample'
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'

const ResponsiveUsageExamples = () => (
<ExampleSection title='Usage'>
<Segment>
<Message info>
The <code>Responsive</code> component relies on browser environment
variables and requires some additions tricks to work correctly with the
server side rendering. We prepared an example that uses{' '}
<code>Responsive</code> and NextJS.
</Message>
<Button
content='Try on CodeSandbox'
color='black'
href='https://codesandbox.io/s/ly3zpw7yzm'
icon='codepen'
size='small'
target='_blank'
/>
</Segment>

<ComponentExample
title='Predefined breakpoints'
description='Responsive has predefined breakpoints that mimics SUI default variables.'
Expand Down
17 changes: 15 additions & 2 deletions docs/src/layouts/HomepageLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ import {
Visibility,
} from 'semantic-ui-react'

// Heads up!
// We using React Static to prerender our docs with server side rendering, this is a quite simple solution.
// For more advanced usage please check Responsive docs under the "Usage" section.
const getWidth = () => {
const isSSR = typeof window === 'undefined'

return isSSR ? Responsive.onlyTablet.minWidth : window.innerWidth
}

/* eslint-disable react/no-multi-comp */
/* Heads up! HomepageHeading uses inline styling, however it's not the best practice. Use CSS or styled components for
* such things.
Expand Down Expand Up @@ -69,7 +78,7 @@ class DesktopContainer extends Component {
const { fixed } = this.state

return (
<Responsive minWidth={Responsive.onlyTablet.minWidth}>
<Responsive getWidth={getWidth} minWidth={Responsive.onlyTablet.minWidth}>
<Visibility
once={false}
onBottomPassed={this.showFixedMenu}
Expand Down Expand Up @@ -131,7 +140,11 @@ class MobileContainer extends Component {
const { sidebarOpened } = this.state

return (
<Responsive as={Sidebar.Pushable} maxWidth={Responsive.onlyMobile.maxWidth}>
<Responsive
as={Sidebar.Pushable}
getWidth={getWidth}
maxWidth={Responsive.onlyMobile.maxWidth}
>
<Sidebar
as={Menu}
animation='push'
Expand Down
16 changes: 4 additions & 12 deletions docs/src/pages/Layouts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ export const meta = {

<Header as='h1' content='Layouts' textAlign='center' />

<Header
as='h2'
content='Starter'
subheader='Examples to introduce components and their function'
/>
<Header as='h2' content='Starter' subheader='Examples to introduce components and their function' />

<Card.Group stackable itemsPerRow='3'>
<Card.Group stackable itemsPerRow='2'>
<Card
as={Link}
to='/layouts/theming'
Expand Down Expand Up @@ -58,13 +54,9 @@ export const meta = {
/>
</Card.Group>

<Header
as='h2'
content='Pages'
subheader='Starter page templates'
/>
<Header as='h2' content='Pages' subheader='Starter page templates' />

<Card.Group stackable itemsPerRow='3'>
<Card.Group stackable itemsPerRow='2'>
<Card
as={Link}
to='/layouts/homepage'
Expand Down

0 comments on commit d53b354

Please sign in to comment.