0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

react ダイアログ

Posted at
const items = [
  { key: '1', name: 'アイテム1', value: '100' },
  { key: '2', name: 'アイテム2', value: '200' },
  // 他の行データを追加
];



import React from 'react';
import { Dialog, DialogType, DialogFooter, PrimaryButton } from '@fluentui/react';
import { DetailsList, DetailsListLayoutMode, SelectionMode, IColumn } from '@fluentui/react/lib/DetailsList';

const MyTableDialog = ({ showDialog, onClose, items }) => {
  const columns: IColumn[] = [
    { key: 'name', name: '名前', fieldName: 'name', minWidth: 100, maxWidth: 200, isResizable: true },
    { key: 'value', name: '', fieldName: 'value', minWidth: 100, maxWidth: 200, isResizable: true },
  ];

  return (
    <Dialog
      hidden={!showDialog}
      onDismiss={onClose}
      dialogContentProps={{
        type: DialogType.normal,
        title: '表のタイトル',
      }}
      modalProps={{
        isBlocking: false,
        styles: { main: { maxWidth: 600 } },
      }
    >
      <div>
        <DetailsList
          items={items}
          columns={columns}
          selectionMode={SelectionMode.none}
          layoutMode={DetailsListLayoutMode.fixedColumns}
        />
      </div>
      <DialogFooter>
        <PrimaryButton onClick={onClose} text="閉じる" />
      </DialogFooter>
    </Dialog>
  );
};

export default MyTableDialog;












import React, { useState } from 'react';
import MyTableDialog from './MyTableDialog';

const ParentComponent = () => {
  const [isDialogVisible, setIsDialogVisible] = useState(false);

  const openDialog = () => {
    setIsDialogVisible(true);
  }

  const closeDialog = () => {
    setIsDialogVisible(false);
  }

  const items = [
    { key: '1', name: 'アイテム1', value: '100' },
    { key: '2', name: 'アイテム2', value: '200' },
    // 他の行データを追加
  ];

  return (
    <div>
      <a href="#" onClick={openDialog}>ダイアログを開く</a>
      <MyTableDialog showDialog={isDialogVisible} onClose={closeDialog} items={items} />
    </div>
  );
};

export default ParentComponent;



0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?