Socket
Socket
Sign inDemoInstall

@kodiak-ui/accordion

Package Overview
Dependencies
Maintainers
6
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kodiak-ui/accordion - npm Package Compare versions

Comparing version 0.3.8 to 0.3.9

dist/accordion.cjs.dev.js

12

dist/accordion.cjs.d.ts

@@ -1,11 +0,1 @@

// are you seeing an error that a default export doesn't exist but your source file has a default export?
// you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
// curious why you need to?
// this file exists so that you can import from the entrypoint normally
// except that it points to your source file and you don't need to run build constantly
// which means we need to re-export all of the modules from your source file
// and since export * doesn't include default exports, we need to read your source file
// to check for a default export and re-export it if it exists
// it's not ideal, but it works pretty well ¯\_(ツ)_/¯
export * from "../src/index";
export * from "./declarations/src/index";

@@ -1,16 +0,7 @@

"use strict";
// this file might look strange and you might be wondering what it's for
// it's lets you import your source files by importing this entrypoint
// as you would import it if it was built with preconstruct build
// this file is slightly different to some others though
// it has a require hook which compiles your code with Babel
// this means that you don't have to set up @babel/register or anything like that
// but you can still require this module and it'll be compiled
'use strict';
// this bit of code imports the require hook and registers it
let unregister = require("../../../node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../..", "..");
// this re-exports the source file
module.exports = require("../src/index.ts");
unregister();
if (process.env.NODE_ENV === "production") {
module.exports = require("./accordion.cjs.prod.js");
} else {
module.exports = require("./accordion.cjs.dev.js");
}

@@ -1,15 +0,327 @@

// 👋 hey!!
// you might be reading this and seeing .esm in the filename
// and being confused why there is commonjs below this filename
// DON'T WORRY!
// this is intentional
// it's only commonjs with `preconstruct dev`
// when you run `preconstruct build`, it will be ESM
// why is it commonjs?
// we need to re-export every export from the source file
// but we can't do that with ESM without knowing what the exports are (because default exports aren't included in export/import *)
// and they could change after running `preconstruct dev` so we can't look at the file without forcing people to
// run preconstruct dev again which wouldn't be ideal
// this solution could change but for now, it's working
import { styled, _variant, sx, css } from 'kodiak-ui';
import { useState, useRef, useCallback } from 'react';
import { setAttributes } from '@kodiak-ui/utils';
module.exports = require("../src/index.ts")
var Accordion = styled('div')({
boxSizing: 'border-box',
margin: 0,
minWidth: 0
}, function (_ref) {
var _ref$variant = _ref.variant,
variantProp = _ref$variant === void 0 ? '' : _ref$variant,
_ref$variantKey = _ref.variantKey,
variantKey = _ref$variantKey === void 0 ? 'accordions' : _ref$variantKey,
theme = _ref.theme;
return _variant({
variant: variantProp,
theme: theme,
variantKey: variantKey
});
}, sx);
var AccordionItem = styled('div')({
boxSizing: 'border-box',
margin: 0,
minWidth: 0
}, function (_ref) {
var _ref$variant = _ref.variant,
variantProp = _ref$variant === void 0 ? 'accordionItem' : _ref$variant,
_ref$variantKey = _ref.variantKey,
variantKey = _ref$variantKey === void 0 ? 'accordions' : _ref$variantKey,
theme = _ref.theme;
return _variant({
variant: variantProp,
theme: theme,
variantKey: variantKey
});
}, sx);
function base(_ref) {
var theme = _ref.theme;
return css({})(theme);
}
var AccordionHeader = styled('header')({
boxSizing: 'border-box',
margin: 0,
minWidth: 0
}, base, function (_ref2) {
var _ref2$variant = _ref2.variant,
variantProp = _ref2$variant === void 0 ? 'accordionHeader' : _ref2$variant,
_ref2$variantKey = _ref2.variantKey,
variantKey = _ref2$variantKey === void 0 ? 'accordions' : _ref2$variantKey,
theme = _ref2.theme;
return _variant({
variant: variantProp,
theme: theme,
variantKey: variantKey
});
}, sx);
function base$1(_ref) {
var theme = _ref.theme;
return css({})(theme);
}
var AccordionBody = styled('section')({
boxSizing: 'border-box',
margin: 0,
minWidth: 0
}, base$1, function (_ref2) {
var _ref2$variant = _ref2.variant,
variantProp = _ref2$variant === void 0 ? 'accordionBody' : _ref2$variant,
_ref2$variantKey = _ref2.variantKey,
variantKey = _ref2$variantKey === void 0 ? 'accordions' : _ref2$variantKey,
theme = _ref2.theme;
return _variant({
variant: variantProp,
theme: theme,
variantKey: variantKey
});
}, sx);
function base$2(_ref) {
var theme = _ref.theme;
return css({})(theme);
}
var AccordionFooter = styled('div')({
boxSizing: 'border-box',
margin: 0,
minWidth: 0
}, base$2, function (_ref2) {
var _ref2$variant = _ref2.variant,
variantProp = _ref2$variant === void 0 ? 'accordionFooter' : _ref2$variant,
_ref2$variantKey = _ref2.variantKey,
variantKey = _ref2$variantKey === void 0 ? 'accordions' : _ref2$variantKey,
theme = _ref2.theme;
return _variant({
variant: variantProp,
theme: theme,
variantKey: variantKey
});
}, sx);
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function useAccordion(_ref) {
var _ref$defaultExpandedI = _ref.defaultExpandedItems,
defaultExpandedItems = _ref$defaultExpandedI === void 0 ? [] : _ref$defaultExpandedI,
controlledExpandedItems = _ref.expandedItems,
onChange = _ref.onChange,
allowMultiple = _ref.allowMultiple;
var _React$useState = useState(controlledExpandedItems || defaultExpandedItems),
_React$useState2 = _slicedToArray(_React$useState, 2),
expandedItemsLocal = _React$useState2[0],
setExpandedItemsLocal = _React$useState2[1];
var expandedItems = controlledExpandedItems || expandedItemsLocal;
var elementRefDictionary = useRef({
accordionHeaders: {},
accordionBodies: {}
});
var handleSetExpandedItemsChange = useCallback(function (expanded) {
var newExpanded = Array.isArray(expanded) ? expanded : [expanded];
onChange && onChange({
expandedItems: newExpanded
});
!controlledExpandedItems && setExpandedItemsLocal(newExpanded);
}, [onChange]);
var checkIsExpanded = useCallback(function checkIsExpanded(_ref2) {
var key = _ref2.key;
return Array.isArray(expandedItems) && expandedItems.includes(key);
}, [expandedItems]);
var toggleExpanded = useCallback(function toggleExpanded(_ref3) {
var key = _ref3.key;
if (allowMultiple) {
// Just toggle the current one in the array
var newExpanded = Array.isArray(expandedItems) ? expandedItems : [];
if (!checkIsExpanded({
key: key
})) {
handleSetExpandedItemsChange([].concat(_toConsumableArray(newExpanded), [key]));
} else {
handleSetExpandedItemsChange(newExpanded.filter(function (expandedItem) {
return expandedItem !== key;
}));
}
} else {
if (!checkIsExpanded({
key: key
})) {
handleSetExpandedItemsChange([key]);
} else {
handleSetExpandedItemsChange([]);
}
}
}, [checkIsExpanded, handleSetExpandedItemsChange, allowMultiple, expandedItems]);
function registerAccordionHeader(_ref4) {
var ref = _ref4.ref,
options = _ref4.options;
if (options.role === 'accordionHeader' || (ref === null || ref === void 0 ? void 0 : ref.tagName) === 'HEADER') {
var accordionHead = ref;
elementRefDictionary.current.accordionHeaders[options.key] = ref;
var headerId = accordionHead.id;
if (headerId === undefined || headerId === '') {
setAttributes(accordionHead, {
id: "".concat(options.key)
});
}
}
return {
ref: ref,
options: options
};
} // Register the body
function registerAccordionBody(_ref5) {
var ref = _ref5.ref,
options = _ref5.options;
if (options.role === 'accordionBody' || (ref === null || ref === void 0 ? void 0 : ref.tagName) === 'SECTION') {
var accordionBody = ref;
elementRefDictionary.current.accordionBodies[options.key] = ref;
var accordionBodyId = accordionBody.id;
if (accordionBodyId === undefined || accordionBodyId === '') {
accordionBodyId = options.key + '-Body';
setAttributes(accordionBody, {
id: accordionBodyId
});
} // try to link up the aria controls/labelled by
var accordionHead = elementRefDictionary.current.accordionHeaders[options.key];
if (accordionHead) {
var headerId = accordionHead.id;
setAttributes(accordionHead, {
'aria-controls': accordionBodyId
});
setAttributes(accordionBody, {
'aria-labelledby': headerId,
role: 'region'
});
}
}
return {
ref: ref,
options: options
};
}
function register(ref, options) {
return ref && registerAccordionBody(registerAccordionHeader({
ref: ref,
options: options
}));
}
function getHeaderProps(_ref6) {
var key = _ref6.key;
return {
onClick: function onClick() {
return toggleExpanded({
key: key
});
},
onKeyUp: function onKeyUp(event) {
if (['Enter', ' '].includes(event.key)) {
toggleExpanded({
key: key
});
}
},
'aria-expanded': checkIsExpanded({
key: key
})
};
}
return {
register: register,
expandedItems: expandedItems,
toggleExpanded: toggleExpanded,
checkIsExpanded: checkIsExpanded,
setExpandedItems: handleSetExpandedItemsChange,
getHeaderProps: getHeaderProps
};
}
export { Accordion, AccordionBody, AccordionFooter, AccordionHeader, AccordionItem, useAccordion };
{
"name": "@kodiak-ui/accordion",
"version": "0.3.8",
"version": "0.3.9",
"description": "Accordion for expanded and collapsed areas",

@@ -28,3 +28,3 @@ "keywords": [

"dependencies": {
"@kodiak-ui/primitives": "^0.20.3",
"@kodiak-ui/primitives": "^0.20.4",
"@kodiak-ui/utils": "^0.0.9"

@@ -36,3 +36,3 @@ },

},
"gitHead": "8d3eb8dda094293a4dcc5c808d1d55e64093517e"
"gitHead": "b0bef5c41d50bc778da04233f0f02b1fc63b2f0c"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc