-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2745 from SUI-Components/feat/behavior-sticky-sha…
…re-state feat: BehaviorSticky sharing isSticky state
- Loading branch information
Showing
5 changed files
with
98 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
components/behavior/sticky/demo/articles/ArticleStickyState.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {useRef} from 'react' | ||
|
||
import PropTypes from 'prop-types' | ||
|
||
import {Article, Bold, Box, Code, H2, Paragraph} from '@s-ui/documentation-library' | ||
|
||
import BehaviorSticky, {BehaviorStickyProvider} from '../../src/index.js' | ||
import LoremIpsum from '../LoremIpsum.js' | ||
import {CLASS_DEMO_PLACEHOLDER} from '../settings.js' | ||
|
||
const ArticleStickyState = ({className}) => { | ||
const ref = useRef() | ||
return ( | ||
<Article className={className}> | ||
<H2>Sticky State</H2> | ||
<Paragraph> | ||
The <Code>BehaviorSticky</Code> allow us to know when the component given gets sticky. Using{' '} | ||
<Code>children</Code> as a <Code>function</Code>, a parameter called <Code>isSticky</Code> is shared with the | ||
current state. It allows rendering the sticky component with different variants depending on the{' '} | ||
<Code>isSticky</Code> state. | ||
</Paragraph> | ||
<BehaviorStickyProvider> | ||
<Box className={CLASS_DEMO_PLACEHOLDER} ref={ref} outline style={{overflowY: 'hidden'}}> | ||
<BehaviorSticky container={ref}> | ||
{({isSticky}) => ( | ||
<Box outline mode={isSticky && 'dark'}> | ||
<Bold>{`The element wrapped by a BehaviorSticky is ${!isSticky ? 'not ' : ''}sticky`}.</Bold> | ||
</Box> | ||
)} | ||
</BehaviorSticky> | ||
<Paragraph> | ||
<LoremIpsum count={10} format="plain" /> | ||
</Paragraph> | ||
<Paragraph> | ||
<LoremIpsum count={10} format="plain" /> | ||
</Paragraph> | ||
<Paragraph> | ||
<LoremIpsum count={10} format="plain" /> | ||
</Paragraph> | ||
</Box> | ||
</BehaviorStickyProvider> | ||
</Article> | ||
) | ||
} | ||
|
||
ArticleStickyState.displayName = 'ArticleStickyState' | ||
|
||
ArticleStickyState.propTypes = { | ||
className: PropTypes.string | ||
} | ||
|
||
export default ArticleStickyState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters