Skip to content

Commit

Permalink
feat: layout component type docs (#3493)
Browse files Browse the repository at this point in the history
* 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
SiTaggart committed Sep 20, 2023
1 parent 33c900c commit dfff35e
Show file tree
Hide file tree
Showing 51 changed files with 11,167 additions and 682 deletions.
6 changes: 6 additions & 0 deletions .changeset/fast-buses-help.md
@@ -0,0 +1,6 @@
---
'@twilio-paste/media-object': patch
'@twilio-paste/core': patch
---

[Media Object]: Improved type annotations
6 changes: 6 additions & 0 deletions .changeset/grumpy-boxes-pay.md
@@ -0,0 +1,6 @@
---
'@twilio-paste/flex': patch
'@twilio-paste/core': patch
---

[Flex]: Improved TsDoc annotations
6 changes: 6 additions & 0 deletions .changeset/healthy-books-kneel.md
@@ -0,0 +1,6 @@
---
'@twilio-paste/aspect-ratio': patch
'@twilio-paste/core': patch
---

[Aspect Ratio]: improved TsDoc annotations
6 changes: 6 additions & 0 deletions .changeset/neat-papayas-play.md
@@ -0,0 +1,6 @@
---
'@twilio-paste/grid': patch
'@twilio-paste/core': patch
---

[Grid]: Improved TsDoc annotations
6 changes: 6 additions & 0 deletions .changeset/orange-flowers-sip.md
@@ -0,0 +1,6 @@
---
'@twilio-paste/codemods': patch
'@twilio-paste/core': patch
---

[Codemods] updated exports map
6 changes: 6 additions & 0 deletions .changeset/poor-ways-collect.md
@@ -0,0 +1,6 @@
---
'@twilio-paste/stack': patch
'@twilio-paste/core': patch
---

[Stack]: Improved TsDoc annotations
10 changes: 10 additions & 0 deletions cypress/integration/sitemap-vrt/constants.ts
Expand Up @@ -20,6 +20,8 @@ export const SITEMAP = [
'/blog/2023-08-02-paste-newsletter/',
'/components/account-switcher/',
'/components/aspect-ratio/',
'/components/aspect-ratio/api',
'/components/aspect-ratio/changelog',
'/components/anchor/',
'/components/anchor/api',
'/components/anchor/changelog',
Expand All @@ -44,12 +46,16 @@ export const SITEMAP = [
'/components/button/changelog',
'/components/button-group/',
'/components/flex/',
'/components/flex/api',
'/components/flex/changelog',
'/components/file-picker/',
'/components/file-uploader/',
'/components/form/',
'/components/combobox/',
'/components/date-picker/',
'/components/grid/',
'/components/grid/api',
'/components/grid/changelog',
'/components/heading/',
'/components/form-pill-group/',
'/components/alert/',
Expand All @@ -64,6 +70,8 @@ export const SITEMAP = [
'/components/list/',
'/components/minimizable-dialog/',
'/components/media-object/',
'/components/media-object/api',
'/components/media-object/changelog',
'/components/meter',
'/components/pagination/',
'/components/modal/',
Expand All @@ -80,6 +88,8 @@ export const SITEMAP = [
'/components/sidebar/',
'/components/sidebar-navigation/',
'/components/stack/',
'/components/stack/api',
'/components/stack/changelog',
'/components/status-badge/',
'/components/status-menu/',
'/components/spinner/',
Expand Down
3 changes: 0 additions & 3 deletions packages/paste-codemods/tools/.cache/mappings.json
Expand Up @@ -307,9 +307,6 @@
"MediaFigure": "@twilio-paste/core/media-object",
"MediaObject": "@twilio-paste/core/media-object",
"Stack": "@twilio-paste/core/stack",
"getStackChildMargins": "@twilio-paste/core/stack",
"getStackDisplay": "@twilio-paste/core/stack",
"getStackStyles": "@twilio-paste/core/stack",
"BOX_PROPS_TO_BLOCK": "@twilio-paste/core/box",
"Box": "@twilio-paste/core/box",
"StyledBox": "@twilio-paste/core/box",
Expand Down
3 changes: 0 additions & 3 deletions packages/paste-codemods/tools/__tests__/tools.spec.ts
Expand Up @@ -42,9 +42,6 @@ describe('generatePackageExportsMap', () => {
Stack: '@twilio-paste/core/stack',
StyledBox: '@twilio-paste/core/box',
getCustomElementStyles: '@twilio-paste/core/box',
getStackChildMargins: '@twilio-paste/core/stack',
getStackDisplay: '@twilio-paste/core/stack',
getStackStyles: '@twilio-paste/core/stack',
safelySpreadBoxProps: '@twilio-paste/core/box',
useComboboxPrimitive: '@twilio-paste/core/combobox-primitive',
useDisclosurePrimitiveState: '@twilio-paste/core/disclosure-primitive',
Expand Down
Expand Up @@ -41,7 +41,7 @@ describe('handlePropValidation function', () => {
<p>This is the AspectRatio utility without a valid ratio.</p>
</AspectRatio>
)
).toThrow(`[Paste: AspectRatio] 'ratio' is invalid. Use a colon separated number pattern (4:3).`);
).toThrow(`[Paste: AspectRatio] 'ratio' is invalid. Use a colon-separated number pattern (4:3).`);
});

it('should throw no errors if passed ratio prop is valid', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/paste-core/layout/aspect-ratio/package.json
Expand Up @@ -18,8 +18,9 @@
"dist"
],
"scripts": {
"build": "yarn clean && NODE_ENV=production node build.js && tsc",
"build": "yarn clean && NODE_ENV=production node build.js && tsc && yarn build:typedocs",
"build:js": "NODE_ENV=development node build.js",
"build:typedocs": "tsx ../../../../tools/build/generate-type-docs",
"clean": "rm -rf ./dist",
"tsc": "tsc"
},
Expand Down Expand Up @@ -52,6 +53,7 @@
"@types/react-dom": "^18.0.10",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"tsx": "^3.12.10",
"typescript": "^4.9.4"
}
}
64 changes: 64 additions & 0 deletions packages/paste-core/layout/aspect-ratio/src/AspectRatio.tsx
@@ -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};
60 changes: 2 additions & 58 deletions packages/paste-core/layout/aspect-ratio/src/index.tsx
@@ -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';
11 changes: 11 additions & 0 deletions packages/paste-core/layout/aspect-ratio/type-docs.json
@@ -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)."
}
}
}
4 changes: 3 additions & 1 deletion packages/paste-core/layout/flex/package.json
Expand Up @@ -18,8 +18,9 @@
"dist"
],
"scripts": {
"build": "yarn clean && NODE_ENV=production node build.js && tsc",
"build": "yarn clean && NODE_ENV=production node build.js && tsc && yarn build:typedocs",
"build:js": "NODE_ENV=development node build.js",
"build:typedocs": "tsx ../../../../tools/build/generate-type-docs",
"clean": "rm -rf ./dist",
"tsc": "tsc"
},
Expand Down Expand Up @@ -52,6 +53,7 @@
"@types/react-dom": "^18.0.10",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"tsx": "^3.12.10",
"typescript": "^4.9.4"
}
}

0 comments on commit dfff35e

Please sign in to comment.