HomeStarbucks Pattern Library

OfflineIndicator

Notes

Provides an Indicator for offline network status

Props

  • labelstring*

    label that displays the offline indicator message

Example: Offline Indicator

<div>
<p className="p2">{'From the devTools "Network" tab, set the network to "offline"'}</p>
<OfflineIndicator
className="p6"
label="You're offline"
/>
</div>

LoadingIndicator

Notes

A general-purpose loading indicator for use during data requests and errors are displayed to users.

Props

  • activebool[false]

    A flag indicating that the loading indicator is active and should be displayed.

  • errorbool[false]

    A flag indicating there is an error is currently being displayed to the user.

Ripple

Notes

Props

  • backgroundClassNamestring

    Overrides the background class

  • childrenfunc[() => {}]

    Function returning properties used to render the ripple and apply required event listeners to the ripple's parent. Returns an object with the following properties:

    • ripple: The renderable React ripple element. Place within the element that should ripple. Note: the element containing the ripple must have position: relative. It can optionally use overflow: hidden to keep the ripple within the bounds of the element.
    • eventHandlers: Event handlers used to enable ripples. Pass to the element that should ripple.
    • mergeEventHandlers: A function used to create ripple event handlers merged with event handlers from element that should ripple. Takes props of target element as parameter, and returns eventHandlers object. This function is only necessary if the component using ripple must support its own onTouchStart and onMouseDown event handlers. Otherwise, just use the eventHandlers property.
  • darkbool

    Inverts ripple color scheme, making it dark instead of light.

<div>
<Heading tagName='h2' size='md' className='mb2'>
Basic usage
</Heading>
<Ripple>
{ ({ ripple, eventHandlers }) => (
<div
className='p6 relative bg-houseGreen color-white overflow-hidden'
{ ...eventHandlers }
>
Click me!
{ ripple }
</div>
) }
</Ripple>
<Ripple dark>
{ ({ ripple, eventHandlers }) => (
<div
className='p6 relative overflow-hidden'
{ ...eventHandlers }
>
Click me!
{ ripple }
</div>
) }
</Ripple>
</div>
<div>
<Heading tagName='h2' size='md' className='mb2'>
Advanced usage with mergeEventHandlers
</Heading>
<Ripple>
{ ({ ripple, mergeEventHandlers }) => (
<div
className='p6 relative bg-houseGreen color-white overflow-hidden'
{ ...mergeEventHandlers({
// In normal usage, you can pass the components `props` to
// `mergeEventHandlers`. For the purposes of this demo, we fake
// it and pass in an `onMouseDown` handler directly.
onMouseDown: () => console.log('Clicked!')
}) }
>
Click me!
{ ripple }
</div>
) }
</Ripple>
</div>

Rule

Notes

A hr element that allows the use of padding instead of margin.

Props

  • visualStyleoneOf('negative')

    Change the color to transparent white if rule is on a dark background. Default is transparent black.

  • weightoneOf('thin')

    Change the weight (thickness) of the rule.

<div>
<p>A Rule can be used in areas when borders are inadequate, and an independent element is needed.</p>
<p className='pt3'>Padding/margin is applied by using spacing classes.</p>
<Rule className='pt3' />
</div>
<div className='p3' style={{ backgroundColor: '#2d2926'}}>
<p className='color-textWhiteSoft'>A negative style is intended for use on dark backgrounds.</p>
<Rule visualStyle='negative' className='py3' />
<ThemeContext.Provider value={ themes.dark }>
<p className='color-textWhiteSoft'>A negative style is automatically triggered when the Rule is a descendant of the Theme component's 'dark' theme.</p>
<Rule className='py3' />
</ThemeContext.Provider>
</div>
<div>
A thin Rule can be used if you specify it's weight.
<Rule weight='thin' className='pt3' />
</div>

ViewportChecker

Notes

Tracks visibility of child elements and returns a flag indicating whether children are in the browser's viewport.

Props

  • childrenfunc*

    Child function with boolean parameter: isIntersecting, function unobserve that can be called when wanting to stop observing the element, and elementRef that needs to be passed in to the element that is being observed

  • completelyVisiblebool

    Flag indicating that the checker shouldn't fire until the element is completely visible with all four edges in the viewport. By default, the checker fires as soon as any edge of the element is in the viewport. DEPRECATION WARNING: 'completelyVisible' will be removed in an upcoming version. Please use percentVisible and a value of 100 if you want to get the same functionality of using completelyVisible.

  • onIntersectionfunc[() => {}]

    Called when element becomes visible, useful for integrating with external libraries and for triggering events.

  • percentVisiblenumber

    Percent of the element that is visible threshold for triggering onIntersection. For example, a value of 50 will trigger onIntersection if the element is 50% visibile. Only values between 0 and 100 (inclusive of 100) are valid.

  • unobserveOnIntersectionbool[false]

    Prop to have the ViewportChecker automatically unobserve after the first intersection. By default, the ViewportChecker will keep checking if the element is in the viewport or not after the first time.

  • xThresholdnumber[0]

    Pixel value threshold for triggering onIntersection on x-axis. For example, a value of 600 will trigger onIntersection if the element comes within 600px of the viewport edge on the x-axis.

  • yThresholdnumber[0]

    Pixel value threshold for triggering onIntersection on y-axis. For example, a value of 600 will trigger onIntersection if the element comes within 600px of the viewport edge on the y-axis.

Example: ViewportChecker reacts to your target element's visibility on the page

<React.Fragment>
<p className="pb3">Scroll this page until the target is partially out of view. It will turn red.</p>
<div>
<ViewportChecker percentVisible={100}>
{({isIntersecting, elementRef}) => (
<div
ref={elementRef}
className={`${isIntersecting ? 'bg-greenAccent color-white' : 'bg-red color-black'} px9 pt4`}
style={{paddingBottom: 100}}
>
<p>
Am I 100% visible? <b>{isIntersecting ? 'Yep!' : 'Nope!'}</b>
</p>
</div>
)}
</ViewportChecker>
</div>
</React.Fragment>

Example: Unobserves on first intersection

<React.Fragment>
<p className="pb3">If you only need to know when your target has reached its `percentVisible`, pass `unobserveOnIntersection` so the underlying IntersectionObserver will stop tracking this element.</p>
<div className='overflow-auto' style={{height: 200}}>
<div style={{margin: '150px 10px'}}>
<ViewportChecker percentVisible={100} unobserveOnIntersection>
{({isIntersecting, elementRef}) => (
<div
ref={elementRef}
className={`${isIntersecting ? 'bg-greenAccent color-white' : 'bg-red color-black'} px9 pt4`}
style={{paddingBottom: 100}}
>
<p>
Has been completely in the viewport? <b>{isIntersecting ? 'Yep!' : 'Nope!'}</b>
</p>
</div>
)}
</ViewportChecker>
</div>
</div>
</React.Fragment>