Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

feat: add parseLength function to @superset-ui/dimension #171

Merged
merged 3 commits into from
Jun 12, 2019

Conversation

kristw
Copy link
Contributor

@kristw kristw commented Jun 12, 2019

🏆 Enhancements

Add function parseLength to parse width or height

  • '100%' => { isDynamic: true, multiplier: 1 }
  • '50%' => { isDynamic: true, multiplier: 0.5 }
  • 100 => { isDynamic: false, value: 100 }
  • '100' => { isDynamic: false, value: 100 }
  • 100px => { isDynamic: false, value: 100 }

@kristw kristw requested a review from a team as a code owner June 12, 2019 20:34
@codecov
Copy link

codecov bot commented Jun 12, 2019

Codecov Report

Merging #171 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #171   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          88     89    +1     
  Lines        1102   1109    +7     
  Branches      264    267    +3     
=====================================
+ Hits         1102   1109    +7
Impacted Files Coverage Δ
packages/superset-ui-dimension/src/parseLength.ts 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f86872a...5408178. Read the comment docs.

@kristw kristw added the reviewable Ready for review label Jun 12, 2019
@netlify
Copy link

netlify bot commented Jun 12, 2019

Deploy preview for superset-ui ready!

Built with commit 5408178

https://deploy-preview-171--superset-ui.netlify.com

return HUNDRED_PERCENT;
} else if (typeof input === 'string' && input.length > 0 && input[input.length - 1] === '%') {
// eslint-disable-next-line no-magic-numbers
return { isDynamic: true, multiplier: parseFloat(input.substring(0, input.length - 1)) / 100 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do parseFloat(input). If the string starts with a number, parseFloat will just ignore the random characters. Comment applies below too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool. Didn't know that!

@kristw kristw merged commit c0ef45f into master Jun 12, 2019
@delete-merged-branch delete-merged-branch bot deleted the kristw--parse-length branch June 12, 2019 23:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
reviewable Ready for review size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants