Yes, react-instagram-feed would be a better name but it was taken...
- Install
npm install --save react-alphabet-soup || yarn add react-alphabet-soup- Use the component
//...
<AlphabetSoup text="AWESOME TEXT" fontSize="24px" sorting="costFunction" costFunctionYWeight={3} />
//...- AlphabetSoup
- AlphabetSoupWithDimensions
- createStyles
- getCenters
- getCharHorizontalPos
- getCharVerticalPos
- measureText
This component renders and animates the text as an Alphabet Soup
propsPropstextstring text to renderwidthnumber width of the space in pixels (optional, default100)heightnumber height of the space in pixels (optional, default100)fontSizestring fontSize of the text when tidy. (optional, default'20px')lineHeightnumber lineHeight of the text when tidy. (optional, default1.3)fontFamilystring fontFamily of the text. (optional, default'Georgia')transitionStylestring style of the transition animation. Values: 'constant' | 'progressive' | 'random'. (optional, default'constant')transitionSpeedMultiplierstring speed multiplier for the transition. Default transitions take 1s. The multiplier can increase and decrease that. (optional, default1)transitionTimingFunctionstring is the transition timing function used on CSS transition. e.g. ease, ease-in, cubic-bezier(1, 0.24, 0.25, 1), ... (optional, default'ease')maxIterationsnumber maximum number of iterations that the Lloyd's relaxation will run through. More iterations mean a more optimal solution, however it can take a lot more time. Less iteration generate less optimal solutions. (optional, default20)acceptableErrornumber error that if achieved between iterations the relaxation process will stop, even if the iterations are not completed. Bigger error with compute results faster. (optional, default1e-6)sortingstring sorting applied to the generated points. 'none' no sorting applied. 'sortByX' sort ascending points using X. 'sortByY' sort ascending points using Y. 'costFunction' sorts points using a cost function likex + costFunctionYWeight * y. (optional, default'none')costFunctionYWeightnumber weight applied to Y in the sorting cost function if sorting='costFunction'. (optional, default1)wrapperClassNamestring class name of the wrapper component. (optional, default'')charactersClassNamestring class name of the characters. It will be applied to all the characters. (optional, default'')untidyOnHoverboolean reverses the behaviour. The text is tidy by default and gets untidy when hover (optional, defaultfalse)verticalboolean when true, the tidied text renders in vertical. (optional, defaultfalse)
Returns any renders the React component
This component renders and animates the text as an Alphabet Soup Same props as AlphabetSoup without width and height which are calculated automatically
propsProps
Returns any renders the React component
Generates the styles for the wrapper and each of the text characters for the animation to happen.
textstring text to be rendered. It is used to generate a style for each character.optionsobject object with options (optional, default{})options.fontSizestring fontSize of the text when tidy (optional, default'20px')options.lineHeightnumber lineHeight of the text when tidy. (optional, default1.3)options.fontFamilystring fontFamily of the text. (optional, default'Georgia')options.transitionStylestring style of the transition animation. Values: 'constant' | 'progressive' | 'random'. (optional, default'constant')options.transitionSpeedMultiplierstring speed multiplier for the transition. Default transitions take 1s. The multiplier can increase and decrease that. (optional, default1)options.untidyOnHoverboolean when true the behaviour is the opposite. (optional, defaultfalse)options.verticalboolean when true, the tidied text renders in vertical. (optional, defaultfalse)options.charCentersArray<{x: number, y: number}> position of the characters before the user hovers them. (optional, defaultundefined)
transitionTimingFunctionstring is the transition timing function used on CSS transition. e.g. ease, ease-in, cubic-bezier(1, 0.24, 0.25, 1), ... (optional, default'ease')
Returns Function
This is a function that calculates a set of points evenly distributed in a defined space. It uses the Lloyd's relaxation on a Voronoi diagram to distribute the points.
numberOfCentersnumber the number of points that need to be distributed in the space.optionsobject object with options (optional, default{})options.widthnumber height of the space (optional, default100)options.heightnumber height of the space (optional, default100)options.maxIterationsnumber maximum number of iterations that the Lloyd's relaxation will run through. More iterations mean a more optimal solution, however it can take a lot more time. Less iteration generate less optimal solutions. (optional, default20)options.acceptableErrornumber error that if achieved between iterations the relaxation process will stop, even if the iterations are not completed. Bigger error with compute results faster. (optional, default1e-6)options.sortingstring sorting applied to the generated points. 'none' no sorting applied. 'sortByX' sort ascending points using X. 'sortByY' sort ascending points using Y. 'costFunction' sorts points using a cost function likex + costFunctionYWeight * y. (optional, default'none')options.costFunctionYWeightnumber weight applied to Y in the sorting cost function if sorting='costFunction'. (optional, default1)
Returns Promise<Array<{x: number, y: number}>> returns a Promise that when resolved returns an array with the points positions
This function return the CSS left parameter for the characters of the input index.
Currently the makes the text to be centered on the space.
indexnumber index of the characters to calculate the CSSleftparametertotalWidthnumber total width of the text to renderpartialWidthsArray<number> array with the width of each character sorted by index position.
This function return the CSS top and left parameter for the characters of the input index.
Currently the makes the text to be centered on the space.
indexnumber index of the characterstotalHeightnumber total height of the text to renderpartialHeightsArray<number> array with the width of each character sorted by index position.partialWidthsArray<number>
Measures the widths and the height of a text
text(string | Array<string>) text to be measured or array with multiple lines of text.optionsobject object with options (optional, default{})options.fontSizestring fontSize of the text. (optional, default'20px')options.lineHeightnumber lineHeight of the text. (optional, default1.3)options.fontFamilystring fontFamily of the text. (optional, default'Georgia')options.fontWeightstring fontWeight of the text. (optional, default400)options.fontStylestring fontStyle of the text. (optional, default'normal')options.canvasstring canvas used to render the text to measure. If none provided, one us created and used. (optional, defaultcreatedbydefault)
Returns {text: string, width: {value: number, units: string}, height: string} returns an object with the width, height and the text or longest text in case of multiline.
MIT © Origen Studio
Contribute
Package generated using Nod
- Babel - Write next generation JavaScript today.
- Jest - JavaScript testing framework used by Facebook.
- ESLint - Make sure you are writing a quality code.
- Prettier - Enforces a consistent style by parsing your code and re-printing it.
- Flow - A static type checker for JavaScript used heavily within Facebook.
- Travis CI - Automate tests and linting for every push or pull request.
- Documentation - A documentation system so good, you'll actually write documentation.
- Conventional Changelog - Generate a changelog from git metadata.
$ yarn test # run tests with Jest
$ yarn run coverage # run tests with coverage and open it on browser
$ yarn run lint # lint code
$ yarn run docs # generate docs
$ yarn run build # generate docs and transpile code$ yarn run version patch|minor|major
$ yarn publishIt'll automatically run test, lint, docs, build, generate CHANGELOG.md, and push commits and tags to the remote repository.