-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PPDSC-2448): export hooks (#404)
* feat: export withOwnTheme * feat(PPDSC-2448): export most used hooks * fix(PPDSC-2448): update tests * fix(PPDSC-2448): resolve conflicts * fix(PPDSC-2448): update docs in storybook * fix(PPDSC-2448): update storybook and tests * fix(PPDSC-2448): design reviews * fix(PPDSC-2448): test * fix(PPDSC-2448): more design comments * fix(PPDSC-2448): resolve comments * fix(PPDSC-2448): update screen reader only * fix(PPDSC-2448): e2e test
- Loading branch information
Showing
25 changed files
with
1,111 additions
and
337 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
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const Component = ({ | ||
value: valueProp, | ||
defaultValue, | ||
onClick, | ||
}: { | ||
value?: number; | ||
defaultValue?: number; | ||
onClick?: () => void; | ||
}) => { | ||
const [value, setValue] = useControlled({ | ||
defaultValue, | ||
controlledValue: valueProp, | ||
}); | ||
|
||
const handleOnClick = () => { | ||
setValue(value! + 1); | ||
|
||
if (onClick) { | ||
onClick(); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button onClick={handleOnClick}>+</Button> | ||
<StyledDiv>{value}</StyledDiv> | ||
</> | ||
); | ||
}; | ||
export const UncontrolledComponent = () => <Component defaultValue={40} />; | ||
export const ControlledComponent = () => ( | ||
<Component value={value} onClick={() => setValue(value + 1)} /> | ||
); |
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,18 @@ | ||
const Section = ({title}: {title: string}) => { | ||
const [ref, isIntersected] = useIntersection({rootMargin: '120px'}); | ||
|
||
const isVisible = isIntersected; | ||
|
||
console.log(`Render Section ${title}`, {isVisible}); | ||
|
||
return <StyledDiv ref={ref}>{title}</StyledDiv>; | ||
}; | ||
|
||
export const Component = () => ( | ||
<> | ||
{Array.from({length: 5}).map((_, index) => ( | ||
// eslint-disable-next-line react/no-array-index-key | ||
<Section key={index + 1} title={`${index + 1}`} /> | ||
))} | ||
</> | ||
); |
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,32 @@ | ||
export const Component = () => { | ||
const [onPressL, setOnPressL] = React.useState(false); | ||
const [onPressShiftAndF, setonPressShiftAndF] = React.useState(false); | ||
const [onPressAOrH, setonPressAOrH] = React.useState(false); | ||
|
||
const onPressSingle = React.useCallback(() => { | ||
setOnPressL(true); | ||
}, [setOnPressL]); | ||
|
||
const onPressMulti = React.useCallback(() => { | ||
setonPressShiftAndF(true); | ||
}, [setonPressShiftAndF]); | ||
|
||
const onPressEitherKey = React.useCallback(() => { | ||
setonPressAOrH(true); | ||
}, [setonPressAOrH]); | ||
|
||
useKeypress('l', onPressSingle, {eventType: 'keydown'}); | ||
useKeypress('shift + f', onPressMulti, {eventType: 'keydown'}); | ||
useKeypress(['a', 'h'], onPressEitherKey, {eventType: 'keydown'}); | ||
|
||
return ( | ||
<> | ||
<TextBlock stylePreset="inkBase">Press L for love</TextBlock> | ||
{onPressL && <StyledDiv>🧡</StyledDiv>} | ||
<TextBlock stylePreset="inkBase">Press SHIFT + F for fox</TextBlock> | ||
{onPressShiftAndF && <StyledDiv>🦊</StyledDiv>} | ||
<TextBlock stylePreset="inkBase">Press A or H for happy face</TextBlock> | ||
{onPressAOrH && <StyledDiv>😊</StyledDiv>} | ||
</> | ||
); | ||
}; |
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,18 @@ | ||
export const Component = () => { | ||
const [, setDimensions] = React.useState({top: 0, left: 0}); | ||
const ref = React.useRef<HTMLDivElement>(null); | ||
|
||
// Optional callback to access the full DOMRect object if required. | ||
const optionalCallback = (entry: DOMRectReadOnly) => | ||
setDimensions({top: entry.x, left: entry.left}); | ||
|
||
// Access the width and the height returned from the observed element. | ||
const [width, height] = useResizeObserver(ref, optionalCallback); | ||
return ( | ||
<> | ||
<StyledDiv ref={ref}> | ||
{width} x {height} | ||
</StyledDiv> | ||
</> | ||
); | ||
}; |
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
27 changes: 17 additions & 10 deletions
27
src/screen-reader-only/__tests__/screen-reader-only.stories.tsx
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 |
---|---|---|
@@ -1,25 +1,32 @@ | ||
import * as React from 'react'; | ||
import {ScreenReaderOnly} from '../screen-reader-only'; | ||
import {StorybookHeading} from '../../test/storybook-comps'; | ||
import {getSSRId} from '../../utils/get-ssr-id'; | ||
import {LinkStandalone} from '../../link'; | ||
|
||
const srOnly = getSSRId(); | ||
|
||
export default { | ||
title: 'Utilities/Screen Reader Only', | ||
component: () => 'None', | ||
}; | ||
|
||
export const StoryScreenReaderOnly = () => ( | ||
<> | ||
<StorybookHeading>Screen reader only</StorybookHeading> | ||
<a href="..." aria-describedby={srOnly}> | ||
<LinkStandalone href="..." aria-describedby={srOnly}> | ||
</a> | ||
</LinkStandalone> | ||
<ScreenReaderOnly id={srOnly}> | ||
The best known search engine | ||
</ScreenReaderOnly> | ||
</> | ||
); | ||
StoryScreenReaderOnly.storyName = 'Default'; | ||
StoryScreenReaderOnly.storyName = 'ScreenReaderOnly'; | ||
StoryScreenReaderOnly.parameters = {eyes: {include: false}}; | ||
|
||
export default { | ||
title: 'Utilities/ScreenReaderOnly', | ||
component: ScreenReaderOnly, | ||
parameters: { | ||
nkDocs: { | ||
title: 'Screen reader', | ||
url: 'https://newskit.co.uk/components/visibility/', | ||
description: | ||
'ScreenReaderOnly wraps an element making sure that it is not visible to the user, but still readable by a screen reader.', | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.