Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"@types/storybook__addon-actions": "^3.4.2",
"@types/storybook__addon-knobs": "^5.0.0",
"@types/storybook__react": "^4.0.1",
"@types/uuid": "^3.4.4",
"@typescript-eslint/eslint-plugin": "^1.5.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
Expand Down
20 changes: 9 additions & 11 deletions src/scripts/util.js → src/scripts/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import createUUID from 'uuid';
import { updateScroll } from 'react-relative-portal';

export const uuid =
process.env.NODE_ENV === 'test' ? () => '$uuid$' : createUUID;
Expand All @@ -11,21 +10,20 @@ export const getToday =

let assetRoot = '/assets';

export function setAssetRoot(path) {
export function setAssetRoot(path: string) {
assetRoot = path;
}

export function getAssetRoot() {
return assetRoot;
}

export function registerStyle(styleName, rules) {
export function registerStyle(styleName: string, rules: string[][]) {
const styleId = `react-slds-cssfix-${styleName}`;
let style = document.getElementById(styleId);
if (style) {
if (document.getElementById(styleId)) {
return;
}
style = document.createElement('style');
const style = document.createElement('style');
style.id = styleId;
style.appendChild(document.createTextNode(''));
document.documentElement.appendChild(style);
Expand All @@ -34,11 +32,11 @@ export function registerStyle(styleName, rules) {
let selectors = ruleSet;
selectors = selectors.concat(selectors.map((s) => `.slds ${s}`));
const rule = `${selectors.join(', ')} ${declaration}`;
style.sheet.insertRule(rule, 0);
(style.sheet as CSSStyleSheet).insertRule(rule, 0);
}
}

export function isElInChildren(rootEl, targetEl) {
export function isElInChildren(rootEl: any, targetEl: any) {
/* eslint-disable no-param-reassign */
while (targetEl && targetEl !== rootEl) {
targetEl = targetEl.parentNode;
Expand All @@ -47,7 +45,7 @@ export function isElInChildren(rootEl, targetEl) {
return !!targetEl;
}

export function offset(el) {
export function offset(el: HTMLElement) {
const rect = el.getBoundingClientRect();

return {
Expand All @@ -56,9 +54,10 @@ export function offset(el) {
};
}

export function cleanProps(props, propTypes) {
export function cleanProps(props: object, propTypes: object) {
const newProps = props;
Object.keys(propTypes).forEach((key) => {
// @ts-ignore
delete newProps[key];
});
return newProps;
Expand All @@ -71,5 +70,4 @@ export default {
isElInChildren,
offset,
cleanProps,
updateScroll,
};
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,13 @@
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==

"@types/uuid@^3.4.4":
version "3.4.4"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-3.4.4.tgz#7af69360fa65ef0decb41fd150bf4ca5c0cefdf5"
integrity sha512-tPIgT0GUmdJQNSHxp0X2jnpQfBSTfGxUMc/2CXBU2mnyTFVYVa2ojpoQ74w0U2yn2vw3jnC640+77lkFFpdVDw==
dependencies:
"@types/node" "*"

"@types/vfile-message@*":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/vfile-message/-/vfile-message-1.0.1.tgz#e1e9895cc6b36c462d4244e64e6d0b6eaf65355a"
Expand Down