Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/artesca 10858 empty state #715

Merged
merged 43 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
73af09c
add a selector in toolbar to switch between backgroundLevel
JeanMarcMilletScality Feb 27, 2024
c90f0ba
add an "empty state" story for Table
JeanMarcMilletScality Feb 27, 2024
4007f1a
linting
JeanMarcMilletScality Feb 27, 2024
bc301a0
add overflow in story
JeanMarcMilletScality Feb 27, 2024
67c3332
change incorrect arg
JeanMarcMilletScality Feb 27, 2024
d9a2864
remove wrapper from table stories
JeanMarcMilletScality Feb 27, 2024
8de85ec
Add line separator to HeadRow as we want a separator even if the tabl…
JeanMarcMilletScality Feb 27, 2024
68cc67b
remove unused import
JeanMarcMilletScality Feb 27, 2024
0ae8088
add story for attachment table
JeanMarcMilletScality Feb 27, 2024
9566249
remove Box from header in attachment table
JeanMarcMilletScality Feb 27, 2024
2d35af3
add warning icon to error message
JeanMarcMilletScality Feb 27, 2024
5f150b7
update IconColor type
JeanMarcMilletScality Feb 27, 2024
99b46ce
center erorr message
JeanMarcMilletScality Feb 27, 2024
0557f35
update style of attachmentTable: Add space for error and no entities …
JeanMarcMilletScality Feb 27, 2024
76e3752
add rowHeight to NoResult to have consistency
JeanMarcMilletScality Feb 28, 2024
9c21b00
remove orphan trailing bracket
JeanMarcMilletScality Feb 28, 2024
e0ea40c
improve stories for attachemment table
JeanMarcMilletScality Feb 28, 2024
7a0289c
increase size of search input in table
JeanMarcMilletScality Feb 28, 2024
5f1de6b
change disabledReason type for reactNode
JeanMarcMilletScality Feb 29, 2024
fcca4a2
add border on hover
JeanMarcMilletScality Feb 29, 2024
f1730ab
add import of react
JeanMarcMilletScality Feb 29, 2024
ea43f7a
add entity and status props to Table
JeanMarcMilletScality Mar 1, 2024
6d5e410
add an object with messages in en and fr for empty and loading state
JeanMarcMilletScality Mar 1, 2024
557482d
add TableRows for empty table or rows rendering, move common elements…
JeanMarcMilletScality Mar 1, 2024
692dd4c
add gap and vertical align so empty and loading state style is consis…
JeanMarcMilletScality Mar 1, 2024
e9598fa
update stories
JeanMarcMilletScality Mar 1, 2024
d34c6b9
change entity for entityName
JeanMarcMilletScality Mar 1, 2024
d9e9fd3
add spacing between columns
JeanMarcMilletScality Mar 4, 2024
8682f1d
remove displayTotalOf dprecated prop, remove displayName as entityNam…
JeanMarcMilletScality Mar 4, 2024
6ac5f46
fr entityName optionnal
JeanMarcMilletScality Mar 4, 2024
af0f23c
change prop and condition as fr is now optionnal
JeanMarcMilletScality Mar 4, 2024
a403fda
add resourceToCreate in EmptyState, change displayed text when an oth…
JeanMarcMilletScality Mar 4, 2024
812c78c
remove border right for non selected row, and remove backgroundVarian…
JeanMarcMilletScality Mar 6, 2024
6399fb3
add an optional background prop to empty state
JeanMarcMilletScality Mar 6, 2024
6600e65
add padding left in rows, comment head row width calc as it change no…
JeanMarcMilletScality Mar 6, 2024
4792eeb
remove console.log
JeanMarcMilletScality Mar 8, 2024
bfc9b47
add box sizing borderbox to avoid border being not visible in UIs. re…
JeanMarcMilletScality Mar 19, 2024
60c1296
fix typo
JeanMarcMilletScality Mar 21, 2024
69d4b31
remove trailing bracket, change for new spacing
JeanMarcMilletScality Mar 21, 2024
e85f76d
add padding in search box container
JeanMarcMilletScality Mar 21, 2024
fabe869
restore margin-top
JeanMarcMilletScality Mar 21, 2024
2da8a24
need to calc width with scrollbar
JeanMarcMilletScality Apr 5, 2024
7bcb19a
add singular and plural to listedResource
JeanMarcMilletScality Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { QueryClient, QueryClientProvider } from 'react-query';
import { CoreUiThemeProvider } from '../src/lib/next';
import { brand, coreUIAvailableThemes } from '../src/lib/style/theme';
import { Wrapper } from '../stories/common';
import { ToastProvider } from '../src/lib';
import { ScrollbarWrapper, ToastProvider } from '../src/lib';

export const globalTypes = {
theme: {
Expand All @@ -12,27 +12,47 @@ export const globalTypes = {
defaultValue: 'darkRebrand',
toolbar: {
title: 'Preview Theme',
dynamicTitle: false,
dynamicTitle: true,
// array of plain string values or MenuItem shape (see below)
items: [
{ value: 'darkRebrand', title: 'Dark', icon: 'moon' },
{ value: 'artescaLight', title: 'Light', icon: 'sun' },
{ value: 'ring9dark', title: 'Ring Dark', icon: 'moon' },
{ value: 'darkRebrand', title: ' A-Dark', icon: 'moon' },
{ value: 'artescaLight', title: 'A-Light', icon: 'sun' },
{ value: 'ring9dark', title: 'R-Dark', icon: 'moon' },
],
},
},
background: {
name: 'Background Level',
description: 'Background for the wrapper',
toolbar: {
title: 'Background Level',
items: [
{ value: 'backgroundLevel1', title: 'backgroundLevel 1' },
{ value: 'backgroundLevel2', title: 'backgroundLevel 2' },
{ value: 'backgroundLevel3', title: 'backgroundLevel 3' },
{ value: 'backgroundLevel4', title: 'backgroundLevel 4' },
],
dynamicTitle: true,
},
},
};

const withThemeProvider = (Story, context) => {
const theme = coreUIAvailableThemes[context.globals.theme];
const { background } = context.globals;
const { viewMode } = context;
return (
<QueryClientProvider client={new QueryClient()}>
<CoreUiThemeProvider theme={theme}>
{/* Wrapper to make the stories take the full screen but not in docs */}
<div style={viewMode === 'story' ? { height: 100 + 'vh' } : null}>
<div
style={
viewMode === 'story'
? { height: 100 + 'vh', overflow: 'scroll' }
: null
}
>
<ToastProvider>
<Wrapper>
<Wrapper style={{ backgroundColor: background }}>
<Story {...context} />
</Wrapper>
</ToastProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ const ConstrainedTextContainer = styled.div`
overflow-wrap: break-word;
`
: `overflow-wrap: break-word;
white-space: nowrap;`}
}
;
white-space: nowrap;`};
`;
const BlockTooltip = styled.div`
width: stretch;
Expand Down
44 changes: 34 additions & 10 deletions src/lib/components/emptystate/Emptystate.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,30 @@ import { spacing } from '../../spacing';
import { Button } from '../buttonv2/Buttonv2.component';
import { Icon, IconName } from '../icon/Icon.component';
import { LargeText } from '../text/Text.component';
import { CoreUITheme } from '../../style/theme';
type Props = {
label: string;
listedResource: {
singular: string;
plural: string;
};
icon: IconName;
link?: string;
history?: Record<string, any>;
backgroundColor?: keyof CoreUITheme;
/**
* The resource to create before browsing the listed resource
* Only used when resource to create is different from listed resource
*/
resourceToCreate?: string;
};
const EmptystateContainer = styled.div`
const EmptystateContainer = styled.div<{ backgroundColor?: keyof CoreUITheme }>`
${(props) => {
const brand = props.theme;
const { theme, backgroundColor } = props;
return css`
color: ${brand.textSecondary};
color: ${theme.textSecondary};
background-color: ${backgroundColor
? theme[backgroundColor]
: 'transparent'};
`;
}}
display: flex;
Expand All @@ -33,25 +46,36 @@ export const ActionWrapper = styled.div`
`;

function EmptyState(props: Props) {
const { icon, label, link, history } = props;
const {
icon,
listedResource,
link,
history,
resourceToCreate,
backgroundColor,
} = props;
return (
<EmptystateContainer className="sc-emptystate">
<EmptystateContainer
className="sc-emptystate"
backgroundColor={backgroundColor}
>
<EmptyStateRow>
<Icon name={icon} color="infoPrimary" size="5x" withWrapper />
</EmptyStateRow>
<EmptyStateRow>
<LargeText>A list of {`${label}s`} will appear here.</LargeText>
<LargeText>{`A list of ${listedResource.plural} will appear here.`}</LargeText>
</EmptyStateRow>
<EmptyStateRow>
<LargeText>
There are no {`${label}s`} created yet, let's create your first{' '}
{label}.
{!resourceToCreate
? `There are no ${listedResource.plural} created yet, let's create your first ${listedResource.singular}.`
: `Before browsing your ${listedResource.plural}, create your first ${resourceToCreate}.`}
</LargeText>
</EmptyStateRow>
{history && (
<ActionWrapper>
<Button
label={`Create ${label}`}
label={`Create ${resourceToCreate || listedResource.singular}`}
icon={<Icon name="Create-add" />}
type="button"
variant="primary"
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/icon/Icon.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, {
useState,
} from 'react';
import styled, { css } from 'styled-components';
import { brand } from '../../style/theme';
import { CoreUITheme } from '../../style/theme';

import { Loader } from '../loader/Loader.component';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
Expand Down Expand Up @@ -142,7 +142,7 @@ const IconStyled = styled(FontAwesomeIcon)`
`;

export type IconName = keyof typeof iconTable;
export type IconColor = keyof typeof brand;
export type IconColor = keyof CoreUITheme;
type Props = {
name: IconName;
size?: SizeProp;
Expand Down
72 changes: 39 additions & 33 deletions src/lib/components/infomessage/InfoMessageUtils.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
import { DefaultTheme, useTheme } from "styled-components";
import { hex2RGB } from "../../utils";
import { useEffect, useRef, useState } from "react";
import { DefaultTheme, useTheme } from 'styled-components';
import { hex2RGB } from '../../utils';
import { useEffect, useRef, useState } from 'react';

export const useComputeBackgroundColor = () => {
const theme = useTheme();
const containerRef = useRef<HTMLDivElement | null>(null);
const [backgroundColor, setBackgroundColor] = useState('');

useEffect(() => {
containerRef.current &&
setBackgroundColor(getBackgroundColor(containerRef.current, theme));
}, [containerRef,theme]);

return {
containerRef,
backgroundColor,
};
const theme = useTheme();
const containerRef = useRef<HTMLDivElement | null>(null);
const [backgroundColor, setBackgroundColor] = useState('');

useEffect(() => {
containerRef.current &&
setBackgroundColor(getBackgroundColor(containerRef.current, theme));
}, [containerRef, theme]);

return {
containerRef,
backgroundColor,
};
};

export const getBackgroundColor = (element: HTMLElement, theme: DefaultTheme) => {
if (element.parentElement) {
const parentElementBackgroundColor = window.getComputedStyle(
element.parentElement,
)['background-color'];
if (/rgba\([0-9]+, [0-9]+, [0-9]+, 0\)/.test(parentElementBackgroundColor) || !window.getComputedStyle(element.parentElement,)['background-color']) {
return getBackgroundColor(element.parentElement, theme);
} else {
const rgbArray = hex2RGB(theme.backgroundLevel2);
if (
`rgb(${rgbArray[0]}, ${rgbArray[1]}, ${rgbArray[2]})` ===
parentElementBackgroundColor
) {
return theme.backgroundLevel3;
}
export const getBackgroundColor = (
element: HTMLElement,
theme: DefaultTheme,
) => {
if (element.parentElement) {
const parentElementBackgroundColor = window.getComputedStyle(
element.parentElement,
)['background-color'];
if (
/rgba\([0-9]+, [0-9]+, [0-9]+, 0\)/.test(parentElementBackgroundColor) ||
!window.getComputedStyle(element.parentElement)['background-color']
) {
return getBackgroundColor(element.parentElement, theme);
} else {
const rgbArray = hex2RGB(theme.backgroundLevel2);
if (
`rgb(${rgbArray[0]}, ${rgbArray[1]}, ${rgbArray[2]})` ===
parentElementBackgroundColor
) {
return theme.backgroundLevel3;
}
}
return theme.backgroundLevel2;
};
}
return theme.backgroundLevel2;
};
1 change: 1 addition & 0 deletions src/lib/components/navbar/Navbar.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const NavbarContainer = styled.div`
color: ${getThemePropSelector('textPrimary')};
}
border-bottom: 0.5px solid ${(props) => props.theme.backgroundLevel3};
box-sizing: border-box;
`};
`;
const NavbarMenu = styled.div`
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/searchinput/SearchInput.component.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { ChangeEvent, forwardRef, useEffect, useRef, useState } from 'react';
import styled, { css } from 'styled-components';
import { Icon } from '../icon/Icon.component';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/selectv2/Selectv2.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type OptionProps = {
icon?: React.ReactNode;
children?: React.ReactNode;
value: string;
disabledReason?: JSX.Element;
disabledReason?: React.ReactNode;
};
const usePreviousValue = (value) => {
const ref = useRef(null);
Expand Down
5 changes: 3 additions & 2 deletions src/lib/components/sidebar/Sidebar.component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import React, { useState } from 'react';
import styled, { css } from 'styled-components';

import {
Expand Down Expand Up @@ -30,6 +30,7 @@ export type WrapperProps = {
hovered?: boolean;
};
const Wrapper = styled.div<WrapperProps>`
margin-top: 1px;
flex-shrink: 0;
${(props) => {
const { backgroundLevel1, textPrimary } = props.theme;
Expand All @@ -41,7 +42,6 @@ const Wrapper = styled.div<WrapperProps>`
}
`;
}}
margin-top: 1px;
border-right: 1px solid ${(props) => props.theme.backgroundLevel3};
${(props) => {
if (props.expanded) {
Expand All @@ -66,6 +66,7 @@ const Wrapper = styled.div<WrapperProps>`
height: 100%;
background-color: ${backgroundLevel1};
z-index: ${zIndex.sidebar};
border-right: 1px solid ${(props) => props.theme.backgroundLevel3};
}
`;
}
Expand Down
Loading
Loading