@awsui/components-react
Version:
On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en
40 lines • 1.76 kB
JavaScript
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React from 'react';
import clsx from 'clsx';
import { warnOnce } from '@awsui/component-toolkit/internal';
export function processAttributes(rest, nativeAttributes, componentName, skipWarnings) {
return Object.entries(nativeAttributes || {}).reduce((acc, [key, value]) => {
// concatenate className
if (key === 'className') {
acc[key] = clsx(rest.className, value);
// merge style
}
else if (key === 'style') {
acc[key] = { ...rest.style, ...value };
// chain event handlers
}
else if (key.match(/^on[A-Z]/) && typeof value === 'function' && key in rest) {
acc[key] = (event) => {
value(event);
if (!event.defaultPrevented) {
rest[key](event);
}
};
// override other attributes, warning if it already exists
}
else {
if (key in rest && (!skipWarnings || (skipWarnings !== true && !skipWarnings.includes(key)))) {
warnOnce(componentName, `Overriding native attribute [${key}] which has a Cloudscape-provided value`);
}
acc[key] = value;
}
return acc;
}, { ...rest });
}
export default React.forwardRef(({ tag, nativeAttributes, children, skipWarnings, componentName, ...rest }, ref) => {
const Tag = tag;
const processedAttributes = processAttributes(rest, nativeAttributes, componentName, skipWarnings);
return (React.createElement(Tag, { ...processedAttributes, ref: ref }, children));
});
//# sourceMappingURL=with-native-attributes.js.map