-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(website): composable do-dont, add anchor examples (#81)
* fix(website): composable do-dont, add anchor examples * feat(website): aspect ratio component, adjust image size to be 4:3 * feat(website): regex shorthand * feat(website): revert yarn lock, change do title props * feat(website): add missing do title * fix(website): callout component extends boxprops * fix(website): updated yarn lock file * fix(website): set node version * fix(website): update circle node config * fix(website): remove jsx import from aspect ration component * fix(website): aspect ratio error changes, use absolute in do dont * fix(website): fix aspect ration typescript error * fix(website): remove box, use div * feat(aspect-ratio): aspect-ratio to core utils * fix(website): swap aspect-ratio in anchor doc page * fix(website): add assets file-system, change image path in anchor doc * fix(website): refactor do/dont, update anchor and button doc * fix(aspect-ratio): add story and test * fix(aspect-ratio): fix lint error * fix(aspect-ratio): change prop name * fix(website): change aspect-ratio prop in do-dont
- Loading branch information
1 parent
924b0a5
commit a799f1b
Showing
13 changed files
with
262 additions
and
54 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
packages/paste-core/utilities/aspect-ratio/__tests__/aspectRatio.spec.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,19 @@ | ||
import * as React from 'react'; | ||
import {mount} from 'enzyme'; | ||
import {AspectRatio} from '../src'; | ||
|
||
describe('AspectRatio', () => { | ||
it('should render a 4:3 aspect ratio div', () => { | ||
const wrapper = mount( | ||
<AspectRatio ratio="4:3"> | ||
<p>This is the AspectRatio utility.</p> | ||
</AspectRatio> | ||
); | ||
expect( | ||
wrapper | ||
.find('div') | ||
.first() | ||
.props().style.paddingBottom | ||
).toBe('75%'); | ||
}); | ||
}); |
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,43 @@ | ||
{ | ||
"name": "@twilio-paste/aspect-ratio", | ||
"version": "0.1.0", | ||
"category": "layout", | ||
"status": "alpha", | ||
"description": "", | ||
"author": "Twilio Inc.", | ||
"license": "MIT", | ||
"main:dev": "src/index.tsx", | ||
"main": "dist/index.js", | ||
"module": "dist/index.es.js", | ||
"types": "dist/index.d.ts", | ||
"sideEffects": false, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "yarn clean && yarn compile", | ||
"build:dev": "yarn clean && yarn compile:dev", | ||
"clean": "rm -rf ./dist && rm -rf tsconfig.build.tsbuildinfo && rm -rf .rpt2_cache", | ||
"compile": "rollup -c --environment NODE_ENV:production", | ||
"compile:dev": "rollup -c --environment NODE_ENV:development", | ||
"prepublishOnly": "yarn build", | ||
"type-check": "tsc --noEmit" | ||
}, | ||
"peerDependencies": { | ||
"@emotion/styled": "^10.0.10", | ||
"@twilio-paste/absolute": "^0.1.0", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6", | ||
"styled-system": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"@twilio-paste/absolute": "^0.1.0", | ||
"rollup": "^1.16.2", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-commonjs": "^10.0.1", | ||
"rollup-plugin-node-resolve": "^5.1.0", | ||
"rollup-plugin-terser": "^5.0.0", | ||
"rollup-plugin-typescript2": "^0.21.2", | ||
"typescript": "^3.5.2" | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/paste-core/utilities/aspect-ratio/rollup.config.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,34 @@ | ||
import typescript from 'rollup-plugin-typescript2'; | ||
import babel from 'rollup-plugin-babel'; | ||
import resolve from 'rollup-plugin-node-resolve'; | ||
import commonjs from 'rollup-plugin-commonjs'; | ||
import {terser} from 'rollup-plugin-terser'; | ||
import pkg from './package.json'; | ||
|
||
export default { | ||
input: pkg['main:dev'], | ||
output: [ | ||
{ | ||
file: pkg.main, | ||
format: 'cjs', | ||
}, | ||
{ | ||
file: pkg.module, | ||
format: 'es', | ||
}, | ||
], | ||
external: [...Object.keys(pkg.peerDependencies || {})], | ||
plugins: [ | ||
resolve(), | ||
commonjs(), | ||
typescript({ | ||
clean: true, | ||
typescript: require('typescript'), | ||
tsconfig: './tsconfig.build.json', | ||
}), | ||
babel({ | ||
exclude: 'node_modules/**', | ||
}), | ||
process.env.NODE_ENV === 'production' ? terser() : null, | ||
], | ||
}; |
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,47 @@ | ||
import * as React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import {Absolute} from '@twilio-paste/absolute'; | ||
|
||
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; | ||
`; | ||
|
||
const AspectRatio: React.FC<AspectRatioProps> = props => { | ||
handlePropValidation(props); | ||
|
||
const aspectArray = props.ratio.split(':').map(Number); | ||
const aspectPercent = (aspectArray[1] / aspectArray[0]) * 100; | ||
|
||
return ( | ||
<AspectRatioContainer style={{paddingBottom: `${aspectPercent}%`}}> | ||
<Absolute>{props.children}</Absolute> | ||
</AspectRatioContainer> | ||
); | ||
}; | ||
|
||
AspectRatio.defaultProps = { | ||
ratio: '4:3', | ||
}; | ||
|
||
export {AspectRatio}; |
24 changes: 24 additions & 0 deletions
24
packages/paste-core/utilities/aspect-ratio/stories/index.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as React from 'react'; | ||
import {storiesOf} from '@storybook/react'; | ||
import {withKnobs, text} from '@storybook/addon-knobs'; | ||
import {Box} from '@twilio-paste/box'; | ||
import {Absolute} from '@twilio-paste/absolute'; | ||
import {AspectRatio} from '../src'; | ||
|
||
storiesOf('Utilities|Aspect Ratio', module) | ||
.addDecorator(withKnobs) | ||
.add('Default', () => { | ||
return ( | ||
<Box | ||
padding="space30" | ||
maxWidth="size40" | ||
borderColor="colorBorderLight" | ||
borderStyle="solid" | ||
borderWidth="borderWidth10" | ||
> | ||
<AspectRatio ratio={text('ratio', '4:3')}> | ||
<Absolute backgroundColor="colorBackgroundBrand" /> | ||
</AspectRatio> | ||
</Box> | ||
); | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/paste-core/utilities/aspect-ratio/tsconfig.build.json
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,15 @@ | ||
{ | ||
"extends": "../../../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"rootDir": "./src" | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"references": [ | ||
{ | ||
"path": "../absolute" | ||
} | ||
] | ||
} |
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,4 @@ | ||
{ | ||
"extends": "../../../../tsconfig.json", | ||
"include": ["src/**/*"] | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.
a799f1b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully aliased the URL https://paste-oo9nthsy8.now.sh to the following aliases: