Skip to content

Commit

Permalink
version 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
morrys committed Sep 23, 2024
1 parent 59575cd commit 49dc9e7
Show file tree
Hide file tree
Showing 17 changed files with 948 additions and 238 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@netservice/astrea-react-ds",
"version": "2.1.0",
"version": "2.2.0",
"main": "dist/umd/index.min.js",
"module": "dist/esm/index.js",
"license": "Apache-2.0",
Expand Down Expand Up @@ -49,7 +49,8 @@
},
"dependencies": {
"@fontsource/titillium-web": "^4.5.9",
"@storybook/test": "^8.1.6"
"@storybook/test": "^8.1.6",
"date-fns": "2.29.3"
},
"peerDependencies": {
"@emotion/react": "^11.11.1",
Expand Down
12 changes: 10 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/components/components/NsInputFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface NsInputFileProps {
onChange?: (e: any) => void;
}

export function NsInputFile({ onChange, value }: NsInputFileProps) {
export function NsInputFile({ onChange, value, ...rest }: NsInputFileProps) {
const inputRef = useRef<HTMLInputElement | null>(null);
const [selectedFile, setSelectedFile] = useState<any>(value);
const { t } = useTranslation();
Expand Down Expand Up @@ -50,6 +50,7 @@ export function NsInputFile({ onChange, value }: NsInputFileProps) {
id={inputId}
style={{ display: 'none' }}
ref={inputRef}
{...rest}
/>
<label htmlFor={inputId}>
<Button
Expand Down
94 changes: 94 additions & 0 deletions src/components/components/form/fields/NsTimePicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { TextFieldProps } from '@mui/material';
import * as React from 'react';
import { useCallback, useMemo } from 'react';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { composeValidators, NsInput } from '../validators';
import { NsLabelInput } from '../../NsLabelInput';
import uniqueId from '../../../../util/uniqueId';
import { useFormField } from 'relay-forms';
import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment';
import moment, { Moment } from 'moment';
import { PickersInputComponentLocaleText } from '@mui/x-date-pickers/locales';
import { useTranslation } from 'react-i18next';
import { TimePicker } from '@mui/x-date-pickers';

const FMT = 'HH:mm';

export type NsTimePickerProps = NsInput<Omit<TextFieldProps, 'value'>, string> & {
localeText?: PickersInputComponentLocaleText<moment.Moment>;
format?: string;
ampm?: boolean;
};

export const NsTimePicker: React.FC<NsTimePickerProps> = ({
name,
label,
defaultValue,
validate,
errorMessage,
disabled,
dependsOn,
onChange,
ampm = false,
format = FMT,
localeText,
...rest
}) => {
const key = useMemo(() => name || uniqueId('v_picker-'), [name]);
const deps = useMemo(() => dependsOn, []);
const { i18n } = useTranslation();

const validateCallback = useCallback(
(v: string, deps: any) => composeValidators(validate, errorMessage)(v, deps),
[validate, errorMessage],
);

const [{ value, error }, setValue] = useFormField<string>({
key,
initialValue: defaultValue as string,
validate: validateCallback,
dependsOn: deps,
});

const setPickerValueCallback = useCallback(
(date: Moment | null) => {
const formattedDate = date ? date.format(FMT) : '';
setValue(formattedDate);

if (onChange) {
const fakeEvent = {
target: { value: formattedDate, name: name },
currentTarget: { value: formattedDate, name: name },
preventDefault: () => {},
stopPropagation: () => {},
} as unknown as React.ChangeEvent<HTMLInputElement>;
onChange(fakeEvent);
}
},
[setValue, onChange],
);

React.useEffect(() => {
if (disabled) {
setValue(defaultValue as string);
}
}, [disabled]);

return (
<NsLabelInput nameHtml={key} label={label as string}>
<LocalizationProvider dateAdapter={AdapterMoment} adapterLocale={i18n.language}>
<TimePicker
format={format}
ampm={ampm}
value={moment(value, FMT)}
onChange={setPickerValueCallback}
disabled={disabled}
slotProps={{
textField: { error: !!error, fullWidth: true, ...rest },
}}
localeText={localeText}
/>
</LocalizationProvider>
</NsLabelInput>
);
};
114 changes: 64 additions & 50 deletions src/components/components/panel/NsPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,89 +1,103 @@
import React, { useState } from 'react';
import { Card, CardContent, Typography } from '@mui/material';
import { Card, CardContent, Typography, SxProps, Theme } from '@mui/material';
import { styled } from '@mui/material/styles';
import { Box } from '@mui/system';
import { useTranslation } from 'react-i18next';
import CloseIcon from '@mui/icons-material/Close';
import ArrowLeftIcon from '@mui/icons-material/ArrowLeft';
import { PanelProps } from 'src/util/types';

export interface PanelProps {
type?: 'primary' | 'secondary';
title: string;
children: React.ReactNode;
menu?: boolean;
isOpen?: boolean;
handleOpen: () => any;
}
const StyledCard = styled(Card)<any>(({ theme, type }) => ({
const StyledCard = styled(Card)<any>(({ theme }) => ({
border: '1px solid',
borderColor: '#b1b4b6',
margin: '0px !important',
boxSizing: 'border-box',
boxShadow: 'none',
borderRadius: '0px',
height: '100%',
display: 'flex',
flexDirection: 'row',
}));

export const NsPanel = ({
menu = false,
type = 'primary',
title,
subtitle,
children,
handleOpen: onClose,
handleOpen,
button,
isOpen = true,
...rest
}: PanelProps) => {
const { t } = useTranslation();
const [isHovered, setIsHovered] = useState(false);

return (
<StyledCard type={type}>
<Box display="flex" flexDirection="row" sx={{ height: '100%' }}>
{menu && (
<Box
sx={{
padding: '10px',
flexGrow: 1,
flexDirection: 'column',
background: isHovered ? '#9c9fa1' : '#b1b4b6',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
cursor: 'pointer',
maxWidth: '40px',
}}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
onClick={onClose}
>
<StyledCard type={type} {...rest}>
{menu && (
<Box
sx={{
// padding: '10px',
flexGrow: 1,
flexDirection: 'column',
background: isHovered ? '#9c9fa1' : '#b1b4b6',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
cursor: 'pointer',
maxWidth: '40px',
minWidth: '40px',
}}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
onClick={handleOpen}
>
<Typography fontWeight={isHovered ? 'bold' : 'normal'}>
{isOpen ? (
<>
<CloseIcon fontWeight={isHovered ? 'bold' : 'normal'} />
<Typography fontWeight={isHovered ? 'bold' : 'normal'}>{t('panel.close')}</Typography>
{typeof button !== 'boolean' ? (
<CloseIcon fontWeight={isHovered ? 'bold' : 'normal'} />
) : (
button
)}
</>
) : (
<>
<ArrowLeftIcon fontWeight={isHovered ? 'bold' : 'normal'} />
<Typography fontWeight={isHovered ? 'bold' : 'normal'}>{t('panel.open')}</Typography>
{typeof button !== 'boolean' ? (
<ArrowLeftIcon fontWeight={isHovered ? 'bold' : 'normal'} />
) : (
button
)}
</>
)}
</Box>
)}
{isOpen && (
<Card
sx={{
borderRadius: '0px',
backgroundColor: type === 'secondary' ? '#2e5a6019' : undefined,
}}
>
<CardContent>
</Typography>
</Box>
)}
{isOpen && (
<Card
sx={{
borderRadius: '0px',
margin: 0,
backgroundColor: type === 'secondary' ? '#2e5a6019' : undefined,
}}
>
<CardContent>
{title && (
<Typography variant={'h3'} fontWeight={900} gutterBottom>
{title}
</Typography>

)}
{subtitle && (
<Typography variant={'h4'} fontWeight={400}>
{subtitle}
</Typography>
)}
<Box component="div" mt={title || subtitle ? 3 : 0}>
{children}
</CardContent>
</Card>
)}
</Box>
</Box>
</CardContent>
</Card>
)}
</StyledCard>
);
};
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export { NsLabelInput } from './components/components/NsLabelInput';
export { Button as NsButton } from '@mui/material';
export { NsTabs } from './components/components/tabs/NsTabs';
export { NsPanel } from './components/components/panel/NsPanel';
export { NsAccordion } from './components/components/NsAccordion';
export { NsAccordion, NsAccordionDetails } from './components/components/NsAccordion';
export { NsProgress } from './components/components/NsProgress';
export { NsPageHeader } from './components/components/pageHeader/NsPageHeader';
export { NsModal } from './components/components/modals/NsModal';
Expand Down Expand Up @@ -44,6 +44,7 @@ export { NsSelectAutocomplete } from './components/components/form/fields/NsSele
export { NsTextInput } from './components/components/form/fields/NsTextInput';
export { NsTextArea } from './components/components/form/fields/NsTextArea';
export { NsFileUpload } from './components/components/form/fields/NsFileUpload';
export { NsTimePicker } from './components/components/form/fields/NsTimePicker';
export * from './components/components/form/validators';

/**
Expand Down
Loading

0 comments on commit 49dc9e7

Please sign in to comment.