feat: add button component

This commit is contained in:
Sergey Yarkov 2021-12-07 00:32:31 +03:00
parent 677e4d9ef5
commit 546a92bc8c
7 changed files with 26 additions and 20 deletions

View File

@ -0,0 +1,9 @@
import React from 'react';
import { ButtonProps, Button } from '@chakra-ui/button';
import { AddIcon } from '@chakra-ui/icons';
export const CreateButton: React.FC<ButtonProps> = props => (
<Button variant='outline' size='sm' leftIcon={<AddIcon />} {...props}>
Create new
</Button>
);

View File

@ -27,6 +27,7 @@ import { useRootStore } from '@educt/hooks/useRootStore';
import { useHistory } from 'react-router'; import { useHistory } from 'react-router';
import CategoryItem from './components/CategoryList/CategoryItem'; import CategoryItem from './components/CategoryList/CategoryItem';
import CourseItem from './components/CourseList/CourseItem'; import CourseItem from './components/CourseList/CourseItem';
import { CreateButton } from '@educt/components/Buttons';
/** /**
* Courses page * Courses page
@ -47,16 +48,7 @@ const CoursesPage: React.FC<IPageProps> = () => {
<Heading as='h1'>Courses</Heading> <Heading as='h1'>Courses</Heading>
<Text mt='2'>List of all courses.</Text> <Text mt='2'>List of all courses.</Text>
</Box> </Box>
{(me.isAdmin || me.isTeacher) && ( {(me.isAdmin || me.isTeacher) && <CreateButton onClick={() => history.push('/courses/create')} />}
<Button
onClick={() => history.push('/courses/create')}
variant='outline'
colorScheme='blue'
leftIcon={<AddIcon />}
>
Create new
</Button>
)}
</Flex> </Flex>
<Box mt='7'> <Box mt='7'>
{(me.isAdmin || me.isTeacher) && <CourseStatusTabs />} {(me.isAdmin || me.isTeacher) && <CourseStatusTabs />}

View File

@ -24,7 +24,7 @@ const BulkActionsMenu: React.FC<BulkActionsMenuPropsType> = ({ selected, rows, s
return ( return (
<Menu isLazy> <Menu isLazy>
<MenuButton as={Button} mr='3' ml='auto' rightIcon={<ChevronDownIcon />}> <MenuButton as={Button} size='sm' variant='outline' mr='3' ml='auto' rightIcon={<ChevronDownIcon />}>
Bulk Actions Bulk Actions
</MenuButton> </MenuButton>
<MenuList> <MenuList>

View File

@ -17,6 +17,7 @@ import type { ICourse } from '@educt/interfaces';
*/ */
import { useCallback, useState } from 'react'; import { useCallback, useState } from 'react';
import { useDisclosure } from '@chakra-ui/react'; import { useDisclosure } from '@chakra-ui/react';
import { AddIcon } from '@chakra-ui/icons';
type StudentTableListPropsType = { type StudentTableListPropsType = {
render: React.FC<StudentTableRowPropsType>; render: React.FC<StudentTableRowPropsType>;
@ -90,7 +91,7 @@ const StudentTableList: React.FC<StudentTableListPropsType> = ({ render: Row, st
<Flex mb='2'> <Flex mb='2'>
<InputGroup mr='2'> <InputGroup mr='2'>
<InputLeftElement pointerEvents='none' children={<MdSearch color='gray.300' />} /> <InputLeftElement pointerEvents='none' children={<MdSearch color='gray.300' />} />
<Input value={search} onChange={handleSearch} type='text' placeholder='Search for student...' /> <Input value={search} size='sm' onChange={handleSearch} type='text' placeholder='Search for student...' />
</InputGroup> </InputGroup>
</Flex> </Flex>
@ -103,7 +104,7 @@ const StudentTableList: React.FC<StudentTableListPropsType> = ({ render: Row, st
<BulkActionsMenu selected={selected} rows={rows} setRows={setRows} /> <BulkActionsMenu selected={selected} rows={rows} setRows={setRows} />
</> </>
)} )}
<Button onClick={onOpenAddStudentModal} variant='outline' colorScheme='blue'> <Button onClick={onOpenAddStudentModal} leftIcon={<AddIcon />} size='sm' variant='outline'>
Add new Add new
</Button> </Button>
</Flex> </Flex>
@ -121,6 +122,9 @@ const StudentTableList: React.FC<StudentTableListPropsType> = ({ render: Row, st
))} ))}
</Tbody> </Tbody>
</Table> </Table>
<Text mt='4' fontSize='sm' color='gray.500'>
{students.length} students
</Text>
</Box> </Box>
); );
}; };

View File

@ -50,6 +50,7 @@ import { UsersPageContext } from '@educt/contexts';
* Schema * Schema
*/ */
import CreateUserSchema from './CreateUserForm.validator'; import CreateUserSchema from './CreateUserForm.validator';
import { CreateButton } from '@educt/components/Buttons';
type CreateUserFormPropsType = {}; type CreateUserFormPropsType = {};
@ -108,9 +109,7 @@ const CreateUserModal: React.FC<CreateUserFormPropsType> = () => {
return ( return (
<> <>
<Button onClick={onOpen} variant='outline' colorScheme='blue' leftIcon={<AddIcon />}> <CreateButton onClick={onOpen} />
Create new
</Button>
<Modal isOpen={isOpen} onClose={onClose}> <Modal isOpen={isOpen} onClose={onClose}>
<ModalOverlay /> <ModalOverlay />
<ModalContent> <ModalContent>

View File

@ -77,7 +77,7 @@ const UserList: React.FC<UserListPropsType> = ({ render: Item, limit }) => {
{users.length !== 0 ? ( {users.length !== 0 ? (
<> <>
<Box> <Box>
<Flex mt='7' p='0 10px' fontWeight='bold' alignItems='center' justifyContent='space-between'> <Flex mt='5' p='0 10px' fontWeight='bold' alignItems='center' justifyContent='space-between'>
<Text>Total: ({pagination.total})</Text> <Text>Total: ({pagination.total})</Text>
<Text>Actions</Text> <Text>Actions</Text>
</Flex> </Flex>
@ -98,7 +98,9 @@ const UserList: React.FC<UserListPropsType> = ({ render: Item, limit }) => {
</Box> </Box>
<Flex margin='2rem 0' flexDirection={{ base: 'column', sm: 'column', md: 'row' }}> <Flex margin='2rem 0' flexDirection={{ base: 'column', sm: 'column', md: 'row' }}>
<Box textAlign={{ base: 'center', sm: 'center', md: 'left' }} mb={{ base: '2', md: '0' }}> <Box textAlign={{ base: 'center', sm: 'center', md: 'left' }} mb={{ base: '2', md: '0' }}>
Page <b>{pagination.current_page}</b> of {pagesCount} <Text fontSize='sm'>
Page <b>{pagination.current_page}</b> of {pagesCount}
</Text>
</Box> </Box>
<Flex ml='auto' mr='auto' justifyContent='center' flexWrap='wrap' alignItems='center' sx={{ gap: '30px' }}> <Flex ml='auto' mr='auto' justifyContent='center' flexWrap='wrap' alignItems='center' sx={{ gap: '30px' }}>
<Button <Button

View File

@ -43,13 +43,13 @@ const UserSearch: React.FC = () => {
return ( return (
<Flex flexBasis='600px'> <Flex flexBasis='600px'>
<Select value={searchingRole} onChange={onSearchRole} w='full' mr='2'> <Select value={searchingRole} onChange={onSearchRole} size='sm' w='full' mr='2'>
<option value='any'>Any role</option> <option value='any'>Any role</option>
<option value={UserRoleEnum.ADMIN}>Administrator</option> <option value={UserRoleEnum.ADMIN}>Administrator</option>
<option value={UserRoleEnum.TEACHER}>Teacher</option> <option value={UserRoleEnum.TEACHER}>Teacher</option>
<option value={UserRoleEnum.STUDENT}>Student</option> <option value={UserRoleEnum.STUDENT}>Student</option>
</Select> </Select>
<InputGroup maxW='400px' w='full'> <InputGroup maxW='400px' w='full' size='sm'>
<InputLeftElement pointerEvents='none' children={<SearchIcon color='gray.300' />} /> <InputLeftElement pointerEvents='none' children={<SearchIcon color='gray.300' />} />
<Input placeholder='Search for a user...' value={search || ''} onChange={onSearch} /> <Input placeholder='Search for a user...' value={search || ''} onChange={onSearch} />
</InputGroup> </InputGroup>