useContainerWidth.js 512 B

1234567891011121314
  1. export default function useContainerWidth(prefixCls) {
  2. const getContainerWidth = (ele, width) => {
  3. const container = ele.querySelector(`.${prefixCls}-container`);
  4. let returnWidth = width;
  5. if (container) {
  6. const style = getComputedStyle(container);
  7. const borderLeft = parseInt(style.borderLeftWidth, 10);
  8. const borderRight = parseInt(style.borderRightWidth, 10);
  9. returnWidth = width - borderLeft - borderRight;
  10. }
  11. return returnWidth;
  12. };
  13. return getContainerWidth;
  14. }