Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

get-value-and-unit

v3.2.0arrow_drop_down
v3.2.0
STATUS
Passing
DOWNLOADS
0
VISIBILITY
Public
PUBLISHED
8 months ago
SIZE
673 B
Returns a given CSS value and its unit as elements of an array.
1 contributor
Use get-value-and-unit in your project ?
Copied
npm i @bit/styled-components.polished.helpers.get-value-and-unit
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Component Example
React
React
Vue
Angular
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
modifieddraft
chevron_left
chevron_right
helpers/getValueAndUnit ()

Returns a given CSS value and its unit as elements of an array.

Example
// Styles as object usage
const styles = {
  '--dimension': getValueAndUnit('100px')[0],
  '--unit': getValueAndUnit('100px')[1],
}

// styled-components usage
const div = styled.div`
  --dimension: ___CSS_0___;
  --unit: ___CSS_1___;
`

// CSS in JS Output

element {
  '--dimension': 100,
  '--unit': 'px',
}
Test Summary

should get value and px from whole values

Pass

should get value and px from values

Pass

should get value and pt from whole values

Pass

should get value and pt from values

Pass

should get value and pc from whole values

Pass

should get value and pc from values

Pass

should get value and mm from whole values

Pass

should get value and mm from values

Pass

should get value and q from whole values

Pass

should get value and q from values

Pass

should get value and cm from whole values

Pass

should get value and cm from values

Pass

should get value and in from whole values

Pass

should get value and in from values

Pass

should get value and em from whole value

Pass

should get value and em from decimal values

Pass

should get value and rem from whole values

Pass

should get value and rem from decimal values

Pass

should get value and ex from whole values

Pass

should get value and ex from decimal values

Pass

should get value and ch from whole values

Pass

should get value and ch from decimal values

Pass

should get value and vh from whole values

Pass

should get value and vh from decimal values

Pass

should get value and vw from whole values

Pass

should get value and vw from decimal values

Pass

should get value and vmin from whole values

Pass

should get value and vmin from decimal values

Pass

should get value and vmax from whole values

Pass

should get value and vmax from decimal values

Pass

should get value and % from whole values

Pass

should get value and % from decimal values

Pass

should return value and no unit when passed a number string

Pass

should return value and no unit when passed a number string

Pass