diff --git a/jsapp/js/bemComponents.ts b/jsapp/js/bemComponents.ts index 1d31b80773..9bbf52c331 100644 --- a/jsapp/js/bemComponents.ts +++ b/jsapp/js/bemComponents.ts @@ -179,15 +179,6 @@ bem.KDrawer__primaryIcons = makeBem(bem.KDrawer, 'primary-icons', 'nav'); bem.KDrawer__secondaryIcons = makeBem(bem.KDrawer, 'secondary-icons', 'nav'); bem.KDrawer__sidebar = makeBem(bem.KDrawer, 'sidebar', 'aside'); -bem.SimpleTable = makeBem(null, 'simple-table', 'table'); -bem.SimpleTable__header = makeBem(bem.SimpleTable, 'header', 'thead'); -bem.SimpleTable__body = makeBem(bem.SimpleTable, 'body', 'tbody'); -bem.SimpleTable__footer = makeBem(bem.SimpleTable, 'footer', 'tfoot'); -bem.SimpleTable__row = makeBem(bem.SimpleTable, 'row', 'tr'); -// NOTE: messageRow needs a __cell with colspan set -bem.SimpleTable__messageRow = makeBem(bem.SimpleTable, 'message-row', 'tr'); -bem.SimpleTable__cell = makeBem(bem.SimpleTable, 'cell', 'td'); - bem.tagSelect = makeBem(null, 'tag-select'); bem.collectionFilter = makeBem(null, 'collection-filter'); diff --git a/jsapp/js/components/common/SimpleTable.module.scss b/jsapp/js/components/common/SimpleTable.module.scss new file mode 100644 index 0000000000..2c804a8de3 --- /dev/null +++ b/jsapp/js/components/common/SimpleTable.module.scss @@ -0,0 +1,25 @@ +// We need bigger specificity in each selector to ensure we do overwrite default +// styles + +table.SimpleTableRoot { + background-color: var(--mantine-color-gray-9); + border-collapse: separate; + border-radius: var(--mantine-radius-md); +} + +thead.SimpleTableThead { + background-color: var(--mantine-color-gray-8); +} + +th.SimpleTableTh { + font-size: var(--mantine-font-size-sm); + color: var(--mantine-color-gray-2); + font-weight: 400; +} + +td.SimpleTableTd { + font-size: var(--mantine-font-size-md); + border-top-width: 1px; + border-top-color: var(--mantine-color-gray-7); + border-top-style: solid; +} diff --git a/jsapp/js/components/common/SimpleTable.stories.tsx b/jsapp/js/components/common/SimpleTable.stories.tsx new file mode 100644 index 0000000000..176c2d78b7 --- /dev/null +++ b/jsapp/js/components/common/SimpleTable.stories.tsx @@ -0,0 +1,46 @@ +import type {Meta, StoryObj} from '@storybook/react'; +import SimpleTable from './SimpleTable'; + +const meta: Meta> = { + title: 'common/SimpleTable', + component: SimpleTable, + argTypes: {}, + args: {}, + render: ({...args}) => ( + + This is just a DIV. It has a button and an input: +

+ +

+ +

+ It shows you can have any React.ReactNode here. + + ), + ], + [58, 140.12, 'Ce', 'Cerium'], + ] + } + /> + ), +}; + +export default meta; + +export const Primary: StoryObj = { + args: {}, +}; diff --git a/jsapp/js/components/common/SimpleTable.tsx b/jsapp/js/components/common/SimpleTable.tsx new file mode 100644 index 0000000000..4680131556 --- /dev/null +++ b/jsapp/js/components/common/SimpleTable.tsx @@ -0,0 +1,47 @@ +import {Table, type MantineStyleProps, type TableData} from '@mantine/core'; +import styles from './SimpleTable.module.scss'; + +interface SimpleTableProps extends MantineStyleProps { + head: TableData['head']; + body: TableData['body']; + /** + * Passing minimum width enables contextual horizontal scrollbar (i.e. without + * it the table will never display scrollbar - regardless of how small + * the screen is). + */ + minWidth?: number; +} + +/** + * A wrapper component for `Table` from `@mantine/core`. It requires column + * headings, column data, and has optional minimum width. You can pass all + * standard Mantine style props down to the inner `Table`. + */ +export default function SimpleTable( + {head, body, minWidth, ...styleProps}: SimpleTableProps +) { + const table = ( + + ); + + if (minWidth) { + return ( + + {table} + + ); + } + + return table; +} diff --git a/jsapp/js/components/modalForms/bulkEditSubmissionsForm.es6 b/jsapp/js/components/modalForms/bulkEditSubmissionsForm.es6 index 86a8e668f4..644ef28c15 100644 --- a/jsapp/js/components/modalForms/bulkEditSubmissionsForm.es6 +++ b/jsapp/js/components/modalForms/bulkEditSubmissionsForm.es6 @@ -15,8 +15,9 @@ import bem from 'js/bem'; import {actions} from 'js/actions'; import TextBox from 'js/components/common/textBox'; import Button from 'js/components/common/button'; +import SimpleTable from 'js/components/common/SimpleTable'; +import {Text} from '@mantine/core'; import envStore from 'js/envStore'; -import './bulkEditSubmissionsForm.scss'; // we need a text to display when we need to say "this question has no answer" const EMPTY_VALUE_LABEL = t('n/d'); @@ -226,62 +227,6 @@ class BulkEditSubmissionsForm extends React.Component { return EXCLUDED_TYPES.includes(questionType); } - renderRow(questionData, itemIndex) { - let question = questionData; - if (typeof questionData.refIndex !== 'undefined') { - question = questionData.item; - } - - let modifiers = []; - // we don't support bulk editing questions from repeat groups yet - // we display them but disabled - if (question.hasRepeatParent) { - modifiers.push('bulk-edit-row-disabled'); - } - - return ( - - - {renderQuestionTypeIcon(question.type)} - - - - {question.parents.length > 0 && - {question.parents.join(' / ') + ' /'} - } - -
- {question.isRequired && } - {question.label} -
-
- - - {question.hasRepeatParent && - {t('Editing responses from repeat group questions is not possible yet.')} - } - {!question.hasRepeatParent && - this.renderRowDataValues(question.name, question.selectedData) - } - - - -