aboutsummaryrefslogtreecommitdiff
path: root/components/List/index.tsx
blob: ae5c190a6c9bd62fbe45a3f194ccfe94bfe89b7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, { FC } from 'react';
import { getSystemStyle, SystemProps } from '../utils/systemProps';
import clsx from 'clsx';

interface ListProps extends SystemProps {
  style?: React.CSSProperties;
  variant : 'ordered' | 'unordered';
  children?: React.ReactNode;
  className?: string;
};

const List : FC<ListProps> = ({ style, className, variant, children, ...props }) => {

  const systemStyle = getSystemStyle(props, style);

  const Tag = {
    'ordered': 'ol',
    'unordered': 'ul'
  }[variant] as keyof React.ReactHTML;

  const styleClass = 'md-' + Tag;

  return (
    <Tag
      className={clsx(styleClass, 'md-list', className)}
      children={children}
      style={systemStyle}
    />
  );
};

interface ListItemProps extends SystemProps {
  style?: React.CSSProperties;
  children?: React.ReactNode;
  className?: string;
};

const ListItem : FC<ListItemProps> = ({ style, className, children, ...props }) => {
  const systemStyle = getSystemStyle(props, style);

  return (
    <li
      className={clsx('md-li', className)}
      style={systemStyle}
    >{children}</li>
  );
}

export {
  List,
  ListItem
};