Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: layout component type docs (#3493)
* feat: layout component type docs * chore: vrt sitemap update * fix: pr feedback * fix: highlight component in nav even on new sub pages * fix: test fail * chore: updated type doc assets
- Loading branch information
Showing
51 changed files
with
11,167 additions
and
682 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@twilio-paste/media-object': patch | ||
'@twilio-paste/core': patch | ||
--- | ||
|
||
[Media Object]: Improved type annotations |
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,6 @@ | ||
--- | ||
'@twilio-paste/flex': patch | ||
'@twilio-paste/core': patch | ||
--- | ||
|
||
[Flex]: Improved TsDoc annotations |
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,6 @@ | ||
--- | ||
'@twilio-paste/aspect-ratio': patch | ||
'@twilio-paste/core': patch | ||
--- | ||
|
||
[Aspect Ratio]: improved TsDoc annotations |
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,6 @@ | ||
--- | ||
'@twilio-paste/grid': patch | ||
'@twilio-paste/core': patch | ||
--- | ||
|
||
[Grid]: Improved TsDoc annotations |
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,6 @@ | ||
--- | ||
'@twilio-paste/codemods': patch | ||
'@twilio-paste/core': patch | ||
--- | ||
|
||
[Codemods] updated exports map |
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,6 @@ | ||
--- | ||
'@twilio-paste/stack': patch | ||
'@twilio-paste/core': patch | ||
--- | ||
|
||
[Stack]: Improved TsDoc annotations |
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
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
64 changes: 64 additions & 0 deletions
64
packages/paste-core/layout/aspect-ratio/src/AspectRatio.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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import * as React from 'react'; | ||
import {Box} from '@twilio-paste/box'; | ||
import {styled} from '@twilio-paste/styling-library'; | ||
|
||
export interface AspectRatioProps { | ||
/** | ||
* Determines the aspect ratio of the element. Use a colon-separated number pattern (width:height). | ||
* | ||
* @type {string} | ||
* @memberof AspectRatioProps | ||
*/ | ||
ratio: string; | ||
children: NonNullable<React.ReactNode>; | ||
} | ||
|
||
const RATIO_REGEX = /^(\d+:\d*)$/; | ||
|
||
const isCorrectPattern = (ratio: string): boolean => RATIO_REGEX.test(ratio); | ||
|
||
const handlePropValidation = ({ratio}: AspectRatioProps): void => { | ||
const hasRatio = ratio != null && ratio !== ''; | ||
|
||
if (!hasRatio) { | ||
throw new Error(`[Paste: AspectRatio] Missing 'ratio' prop.`); | ||
} | ||
|
||
if (!isCorrectPattern(ratio)) { | ||
throw new Error(`[Paste: AspectRatio] 'ratio' is invalid. Use a colon-separated number pattern (4:3).`); | ||
} | ||
}; | ||
|
||
const AspectRatioContainer = styled.div` | ||
position: relative; | ||
embed, | ||
iframe, | ||
object, | ||
video { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
`; | ||
|
||
const AspectRatio = React.forwardRef<HTMLDivElement, AspectRatioProps>((props, ref) => { | ||
handlePropValidation(props); | ||
|
||
const aspectArray = props.ratio.split(':').map(Number); | ||
const aspectPercent = (aspectArray[1] / aspectArray[0]) * 100; | ||
|
||
return ( | ||
<AspectRatioContainer ref={ref} style={{paddingBottom: `${aspectPercent}%`}}> | ||
<Box position="absolute" top={0} right={0} bottom={0} left={0}> | ||
{props.children} | ||
</Box> | ||
</AspectRatioContainer> | ||
); | ||
}); | ||
|
||
AspectRatio.displayName = 'AspectRatio'; | ||
|
||
export {AspectRatio}; |
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,58 +1,2 @@ | ||
import * as React from 'react'; | ||
import {Box} from '@twilio-paste/box'; | ||
import {styled} from '@twilio-paste/styling-library'; | ||
|
||
export interface AspectRatioProps { | ||
ratio: string; | ||
children: NonNullable<React.ReactNode>; | ||
} | ||
|
||
const RATIO_REGEX = /^(\d+:\d*)$/; | ||
|
||
const isCorrectPattern = (ratio: string): boolean => RATIO_REGEX.test(ratio); | ||
|
||
const handlePropValidation = ({ratio}: AspectRatioProps): void => { | ||
const hasRatio = ratio != null && ratio !== ''; | ||
|
||
if (!hasRatio) { | ||
throw new Error(`[Paste: AspectRatio] Missing 'ratio' prop.`); | ||
} | ||
|
||
if (!isCorrectPattern(ratio)) { | ||
throw new Error(`[Paste: AspectRatio] 'ratio' is invalid. Use a colon separated number pattern (4:3).`); | ||
} | ||
}; | ||
|
||
const AspectRatioContainer = styled.div` | ||
position: relative; | ||
embed, | ||
iframe, | ||
object, | ||
video { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
`; | ||
|
||
const AspectRatio = React.forwardRef<HTMLDivElement, AspectRatioProps>((props, ref) => { | ||
handlePropValidation(props); | ||
|
||
const aspectArray = props.ratio.split(':').map(Number); | ||
const aspectPercent = (aspectArray[1] / aspectArray[0]) * 100; | ||
|
||
return ( | ||
<AspectRatioContainer ref={ref} style={{paddingBottom: `${aspectPercent}%`}}> | ||
<Box position="absolute" top={0} right={0} bottom={0} left={0}> | ||
{props.children} | ||
</Box> | ||
</AspectRatioContainer> | ||
); | ||
}); | ||
|
||
AspectRatio.displayName = 'AspectRatio'; | ||
|
||
export {AspectRatio}; | ||
export {AspectRatio} from './AspectRatio'; | ||
export type {AspectRatioProps} from './AspectRatio'; |
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,11 @@ | ||
{ | ||
"AspectRatio": { | ||
"ratio": { | ||
"type": "string", | ||
"defaultValue": null, | ||
"required": true, | ||
"externalProp": false, | ||
"description": "Determines the aspect ratio of the element. Use a colon-separated number pattern (width:height)." | ||
} | ||
} | ||
} |
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
Oops, something went wrong.