Skip to content

Commit

Permalink
impl
Browse files Browse the repository at this point in the history
  • Loading branch information
sgendre committed Oct 10, 2023
1 parent cd04f75 commit 89a959f
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions packages/forms/src/UIForm/fieldsets/Tabs/Tabs.component.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
import PropTypes from 'prop-types';
import { useState } from 'react';
import TabBar from '@talend/react-components/lib/TabBar';
import classNames from 'classnames';
import { Tabs } from '@talend/design-system';
import { useTranslation } from 'react-i18next';

import Widget from '../../Widget';
import { isValid } from '../../utils/validation';
import theme from './Tabs.module.scss';
import { I18N_DOMAIN_FORMS } from '../../../constants';

function Tabs(props) {
const [selectedKey, setSelectedKey] = useState(0);
function TabsAdapter(props) {
const { schema, ...restProps } = props;

const { t } = useTranslation(I18N_DOMAIN_FORMS);

const { schema, ...restProps } = props;
const tabs = schema.items.map((item, index) => {
const tabIsValid = isValid(item, restProps.errors);
return {
key: index,
label: item.title,
className: classNames({ [theme['has-error']]: !tabIsValid }),
'aria-label': tabIsValid
? undefined
: `${item.title} (${t('TF_TABS_HAS_ERRORS', { defaultValue: 'has errors' })})`,
children: (
tabTitle: {
title: item.title,
id: `${restProps.id}-tabs-${index}`,
},
tabContent: tabIsValid ? (
<Widget
{...restProps}
schema={{ widget: 'fieldset', ...item, options: { ...item.options, hideTitle: true } }}
/>
) : (
<div
className={theme['has-error']}
aria-label={`${item.title} (${t('TF_TABS_HAS_ERRORS', { defaultValue: 'has errors' })})`}
>
<Widget
{...restProps}
schema={{ widget: 'fieldset', ...item, options: { ...item.options, hideTitle: true } }}
/>
</div>
),
};
});

return (
<TabBar
className={classNames(theme['tf-tabs'], 'tf-tabs')}
id={`${restProps.id}-tabs`}
items={tabs}
onSelect={(_, item) => setSelectedKey(item.key)}
selectedKey={selectedKey}
/>
);
return <Tabs id={`${restProps.id}-tabs`} tabs={tabs} />;
}

if (process.env.NODE_ENV !== 'production') {
Tabs.propTypes = {
TabsAdapter.propTypes = {
errors: PropTypes.object,
schema: PropTypes.shape({
items: PropTypes.arrayOf(
Expand All @@ -57,4 +56,4 @@ if (process.env.NODE_ENV !== 'production') {
};
}

export default Tabs;
export default TabsAdapter;

0 comments on commit 89a959f

Please sign in to comment.