@codecademy/gamut
73.6.173.6.2-alpha.3e37cd.0
dist/utils/dataAttributes.js+
dist/utils/dataAttributes.jsNew file+20
Index: package/dist/utils/dataAttributes.js
===================================================================
--- package/dist/utils/dataAttributes.js
+++ package/dist/utils/dataAttributes.js
@@ -0,0 +1,20 @@
+/*
+ * Splits `data-*` entries off a props object from everything else. `data-*`
+ * attributes are identity/targeting hooks (Pendo selectors, QA scripts) and
+ * belong on whichever node also carries `id`, which is not always the same
+ * node that receives style props and `aria-*`. Components that render more
+ * than one DOM node - a wrapper plus a semantic element - use this to route
+ * each half to the right place instead of spreading everything onto one node.
+ */
+export const splitDataAttributes = props => {
+ const dataAttrs = {};
+ const rest = {};
+ Object.keys(props).forEach(key => {
+ if (key.startsWith('data-')) {
+ dataAttrs[key] = props[key];
+ } else {
+ rest[key] = props[key];
+ }
+ });
+ return [dataAttrs, rest];
+};
\ No newline at end of file