{"_id":"@atlaskit/ds-lib@8.0.1","bugs":{"url":"https://bitbucket.org/atlassian/atlassian-frontend-mirror/issues"},"dist":{"shasum":"5687ae91219b8540ecfef563a8836c045d47bf9c","tarball":"http://registry-npm.ywwl.com/@atlaskit/ds-lib/download/@atlaskit/ds-lib-8.0.1.tgz","fileCount":133,"integrity":"sha512-kvuOp8D4CMMd82zK/BJztOKl18UZeZwpdWds5Mhy1FFhvHiMqFU0vzIcE4J5vL2Fz4UYPjkOce4bAFvBsYV8WQ==","signatures":[{"sig":"MEUCIQDPZfVQ4HtMvcpW4qMkLaqikgkuKvLMD7VMJh20ZFcd3wIgJURYjBXN6MtsUYolel+7fwy1H9O7Z/G8S3PG9iNjNuw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHzGgJ+XhdlxeFVtgAsQN3eJuWJRvQjVY6/JPXWNakZjAiEAz3EWfJPkCSBUHZkV/It+PD8M8sJKTLMPQPl0uAlI74I="}],"unpackedSize":102034,"size":23963,"noattachment":false,"key":"/@atlaskit/ds-lib/-/@atlaskit/ds-lib-8.0.1.tgz"},"main":"dist/cjs/index.js","name":"@atlaskit/ds-lib","_from":"file:/tmp/package-1-6ad9872c-63a8aa7170609629e8fbe81c-1.tgz","types":"dist/types/index.d.ts","author":{"name":"Atlassian Pty Ltd"},"module":"dist/esm/index.js","license":"Apache-2.0","version":"8.0.1","_npmUser":{"name":"atlassianartifactteam","email":"eng-development-tooling-artifacts@atlassian.com"},"homepage":"https://atlaskit.atlassian.com/packages/design-system/ds-lib","_resolved":"/tmp/package-1-6ad9872c-63a8aa7170609629e8fbe81c-1.tgz","atlassian":{"team":"Design System Team","website":{"name":"DSLib","category":"Libraries","deprecated":"This is an internal package and should not be used directly."}},"_integrity":"sha512-kvuOp8D4CMMd82zK/BJztOKl18UZeZwpdWds5Mhy1FFhvHiMqFU0vzIcE4J5vL2Fz4UYPjkOce4bAFvBsYV8WQ==","repository":{"url":"git+https://bitbucket.org/atlassian/atlassian-frontend-mirror.git","type":"git"},"_npmVersion":"10.8.2","description":"Reusable utilities and hooks specific to design system.","directories":{},"maintainers":[{"name":"atlassianartifactteam","email":"eng-development-tooling-artifacts@atlassian.com"}],"sideEffects":["**/*.compiled.css"],"_nodeVersion":"20.20.2","atlaskit:src":"src/index.tsx","dependencies":{"@babel/runtime":"^7.0.0","tiny-invariant":"^1.2.0","bind-event-listener":"^3.0.0"},"module:es2019":"dist/es2019/index.js","publishConfig":{"registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"react":"^19.0.0","jest-in-case":"^1.0.2","@testing-library/dom":"^10.1.0","@testing-library/react":"^16.3.0","@atlassian/a11y-jest-testing":"^0.17.0","@atlassian/feature-flags-test-utils":"^1.3.0"},"peerDependencies":{"react":"^18.2.0 || ^19.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ds-lib_8.0.1_1792640964783_0.13472599727908308"},"readme":"# DSLib\n\nThis is an internal package with common functionality used in the Atlassian Design System Team. This\npackage comes with no support and semver guarantees, your app will break if you use this directly!\n\n## Installation\n\n```sh\nyarn add @atlaskit/ds-lib\n```\n\n## Utilities\n\n### `noop()`\n\n```tsx\nimport noop from '@atlaskit/ds-lib/noop';\n\nnoop();\n```\n\n### `once()`\n\nCreate a new `function` that only allows an existing `function` to be called once.\n\n```tsx\nimport once from '@atlaskit/ds-lib/once';\n\nfunction getGreeting(name: string): string {\n\treturn `Hello ${name}`;\n}\nconst getGreetingOnce = once(getGreeting);\n\ngetGreetingOnce('Alex');\n// getGreeting called and \"Hello Alex\" is returned\n// \"Hello Alex\" is put into the cache.\n// returns \"Hello Alex\"\n\ngetGreetingOnce('Sam');\n// getGreeting is not called\n// \"Hello Alex\" is returned from the cache.\n\ngetGreetingOnce('Greg');\n// getGreeting is not called\n// \"Hello Alex\" is returned from the cache.\n```\n\nNotes:\n\n- If the `onced` function throws, then the return value of the function is not cached\n- Respects call site context (`this`) when executing the onced function\n\n### `warnOnce()`\n\n```tsx\nimport warnOnce from '@atlaskit/ds-lib/warn-once';\n\nfunction Component() {\n\t// Print the warning messagein in the Web console only once per session.\n\tif (process.env.NODE_ENV !== 'production') {\n\t\twarnOnce('This component has been deprecated.');\n\t}\n\n\treturn <div>This component has been deprecated</div>;\n}\n```\n\n### `mergeRefs()`\n\n```tsx\nimport mergeRefs from '@atlaskit/ds-lib/merge-refs';\n\nconst Component = forwardRef((props, ref) => {\n  const customRef = useRef<HTMLElement | null>(null);\n\n  return (\n    // Use the utility function to merge the forwarded ref\n    // with the created ref.\n    <div ref={mergeRefs[ref, customRef]} />\n  );\n}\n```\n\n### `device-check`\n\n```tsx\nimport { isAppleDevice, isSafari } from '@atlaskit/ds-lib/device-check';\nisAppleDevice();\nisSafari();\n```\n\n## React hooks\n\n### `useLazyRef()`\n\n```tsx\nimport useLazyRef from '@atlaskit/ds-lib/use-lazy-ref';\n\nfunction Component({ onClick }) {\n\t// Initialize the ref\n\tconst ref = useLazyRef(() => {\n\t\t/* Return initial data */\n\t});\n\n\t// Access like a normal ref\n\treturn <button onClick={() => onClick(ref.current)}>Click me!</button>;\n}\n```\n\n### `useControlled()`\n\n```tsx\nimport useControlled from '@atlaskit/ds-lib/use-controlled';\n\nfunction ControlledComponent({ value, defaultValue = 0 }) {\n\tconst [uncontrolledState, setUncontrolledState] = useControlled(value, () => defaultValue);\n\treturn <button onClick={() => setUncontrolledState(uncontrolledState + 1)}>Update state</button>;\n}\n```\n\n### `usePreviousValue()`\n\n```js\nfunction Component() {\n\tconst [currentValue] = useState(1);\n\tconst previousValue = usePreviousValue(currentValue);\n\n\tpreviousValue; // undefined\n\tcurrentValue; // 1\n\n\treturn null;\n}\n```\n\n### `useStableRef()`\n\n```tsx\nfunction Component({ canShow }: { canShow: () => boolean }) {\n\tconst stableRef = useStableRef({ canShow });\n\n\tuseEffect(\n\t\t() => {\n\t\t\tstableRef.current.canShow();\n\t\t},\n\t\t// Able to use the last render value of `canShow` without needing\n\t\t// to invalidate the effect. Useful for lazy usage of props.\n\t\t[],\n\t);\n\n\treturn null;\n}\n```\n\n### `useLazyCallback()`\n\n```tsx\nimport useLazyCallback from '@atlaskit/ds-lib/use-lazy-callback';\n\nfunction Component() {\n\t// `callback` always has the same reference.\n\tconst callback = useLazyCallback(() => {\n\t\t// Watch out for its stale closure however!\n\t});\n\n\treturn null;\n}\n```\n\n### `useStateRef()`\n\n```tsx\nimport useStateRef from '@atlaskit/ds-lib/use-state-ref';\n\nfunction Component() {\n  const [valueRef, setState] = useStateRef(0);\n\n  // Access the latest value, even inside stale closures.\n  console.log(valueRef.current);\n\n  // Update state as you would with use state\n  return <div onClick={() => setState(prev => prev + 1)} />;\n```\n\n### `useScrollbarWidth()`\n\n```tsx\nimport useScrollbarWidth from '@atlaskit/ds-lib/use-scrollbar-width';\n\nfunction Component() {\n\tconst scrollbar = useScrollbarWidth();\n\n\treturn (\n\t\t// Use the scrollbar width in your styles/as you wish.\n\t\t// The ref should be attached to the scrollable element.\n\t\t<div id=\"container\" style={{ padding: scrollbar.width }}>\n\t\t\t<div id=\"scrollable\" ref={scrollbar.ref} />\n\t\t</div>\n\t);\n}\n```\n\n### `useCloseOnEscapePress()`\n\n**Notice: `useCloseOnEscapePress()` is deprecated, Please use `useCloseOnEscapePress` from\n`@atlaskit/layering` instead.**\n\n```tsx\nimport useCloseOnEscapePress from '@atlaskit/ds-lib/use-close-on-escape-press';\n\n// Will callback when escape is pressed\nuseCloseOnEscapePress({\n\tonClose: () => {},\n\tisDisabled: false,\n});\n```\n\n### `useAutoFocus()`\n\n```tsx\nimport useAutoFocus from '@atlaskit/ds-lib/use-auto-focus';\n\nconst elementRef = useRef();\nuseAutoFocus(elementRef, true);\n\n<div ref={elementRef} />;\n```\n","publish_time":1792640964862,"_cnpm_publish_time":1792640964862,"dist-tags":{"latest":"9.0.0","next":"2.2.2"}}