coreui / coreui-utils

CoreUI JavaScript utility functions
MIT License
6 stars 8 forks source link

hexToRgba fails for hex shortcodes #1

Open jameswilson opened 4 years ago

jameswilson commented 4 years ago

Testing the v3-next functionality, the new coreui.Utils.hexToRgba fails on the --info color code, because it is a 3-digit hex value, instead of a standard 6 digit hex value.

<style>
:root {
  --primary: #321fdb;
  --secondary: #ced2d8;
  --success: #2eb85c;
  --info: #39f;
  --warning: #f9b115;
  --danger: #e55353;
  --light: #ebedef;
  --dark: #636f83;
  --breakpoint-xs: 0;
  --breakpoint-sm: 576px;
  --breakpoint-md: 768px;
  --breakpoint-lg: 992px;
  --breakpoint-xl: 1200px;
  --font-family-sans-serif: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  --font-family-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
</style>
<script src="vendors/@coreui/chartjs/js/coreui-chartjs.bundle.js"></script>
<script src="vendors/@coreui/utils/js/coreui-utils.js"></script>
<script>
  console.log(coreui.Utils.getStyle('--info'));
  console.log(coreui.Utils.hexToRgba(coreui.Utils.getStyle('--info'), 90));
  console.log('#3399ff');
  console.log(coreui.Utils.hexToRgba('#3399ff', 90));
</script>

Output in JS console is the following:

#39f
rgba(3, 9, 15, 0.9)
#3399ff
rgba(51, 153, 255, 0.9)

Expected output should be:

#39f
rgba(51, 153, 255, 0.9)
#3399ff
rgba(51, 153, 255, 0.9)
jameswilson commented 4 years ago

See PR #3