Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: layout component type docs #3493

Merged
merged 7 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fast-buses-help.md
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
6 changes: 6 additions & 0 deletions .changeset/grumpy-boxes-pay.md
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
6 changes: 6 additions & 0 deletions .changeset/healthy-books-kneel.md
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
6 changes: 6 additions & 0 deletions .changeset/neat-papayas-play.md
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
6 changes: 6 additions & 0 deletions .changeset/orange-flowers-sip.md
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
6 changes: 6 additions & 0 deletions .changeset/poor-ways-collect.md
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
10 changes: 10 additions & 0 deletions cypress/integration/sitemap-vrt/constants.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@
const mockMapping = await generatePackageExportsMap(mockGetPastePackages);

expect(mockMapping).toEqual({
BOX_PROPS_TO_BLOCK: '@twilio-paste/core/box',

Check warning on line 37 in packages/paste-codemods/tools/__tests__/tools.spec.ts

View workflow job for this annotation

GitHub Actions / Lint repository

Define a constant instead of duplicating this literal 5 times
Box: '@twilio-paste/core/box',
ComboboxPrimitive: '@twilio-paste/core/combobox-primitive',

Check warning on line 39 in packages/paste-codemods/tools/__tests__/tools.spec.ts

View workflow job for this annotation

GitHub Actions / Lint repository

Define a constant instead of duplicating this literal 3 times
DisclosurePrimitive: '@twilio-paste/core/disclosure-primitive',

Check warning on line 40 in packages/paste-codemods/tools/__tests__/tools.spec.ts

View workflow job for this annotation

GitHub Actions / Lint repository

Define a constant instead of duplicating this literal 3 times
DisclosurePrimitiveContent: '@twilio-paste/core/disclosure-primitive',
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
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};
60 changes: 2 additions & 58 deletions packages/paste-core/layout/aspect-ratio/src/index.tsx
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';
11 changes: 11 additions & 0 deletions packages/paste-core/layout/aspect-ratio/type-docs.json
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)."
}
}
}
4 changes: 3 additions & 1 deletion packages/paste-core/layout/flex/package.json
Original file line number Diff line number Diff line change
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"
}
}
Loading
Loading