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 material-uiでAccordionを実装する

Last updated at Posted at 2023-10-31

はじめに

表題通り、Reactのmaterial-uiでAccordionを実装します。

成果物

スクリーンショット 2023-10-31 13.53.46.png スクリーンショット 2023-10-31 13.53.46.png
ディレクトリ構成
~/develop/react/acodion_material_ui$ tree -I node_modules
.
├── README.md
├── package.json
├── public
│   ├── favicon.ico
│   ├── index.html
│   ├── logo192.png
│   ├── logo512.png
│   ├── manifest.json
│   └── robots.txt
├── src
│   ├── App.tsx
│   ├── MyAccordion.tsx
│   ├── index.tsx
│   └── logo.svg
├── tsconfig.json
└── yarn.lock

3 directories, 14 files
App.tsx
import React from 'react';
import { MyAccordion } from './MyAccordion';

function App() {
  return <MyAccordion />;
}

export default App;
src/MyAccordion.tsx
import React, { useState } from 'react';
import {
  Accordion,
  AccordionSummary,
  AccordionDetails,
  Typography,
} from '@material-ui/core';
import { KeyboardArrowUp, KeyboardArrowRight } from '@material-ui/icons';

export const MyAccordion: React.FC = () => {
  const [expanded, setExpanded] = useState(false);
  const toggleAccordion = () => {
    setExpanded(!expanded);
  };

  return (
    <Accordion expanded={expanded} onChange={toggleAccordion}>
      <AccordionSummary
        expandIcon={expanded ? <KeyboardArrowUp /> : <KeyboardArrowRight />}
      >
        <Typography variant="h6">アコーディオン タイトル</Typography>
      </AccordionSummary>
      <AccordionDetails>
        <Typography>アコーディオンサンプルです!!!!</Typography>
      </AccordionDetails>
    </Accordion>
  );
};
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?