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

Ocrvs 8276 Create a banner component #8277

Merged
merged 8 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- **Template Selection Dropdown**: Updated print workflow to include a dropdown menu for template selection when issuing a certificate.
- Auth now allows exchanging user's token for a new record-specific token [#7728](https://github.com/opencrvs/opencrvs-core/issues/7728)
- A new GraphQL mutation `upsertRegistrationIdentifier` is added to allow updating the patient identifiers of a registration record such as NID [#8034](https://github.com/opencrvs/opencrvs-core/pull/8034)
- Introduced a new customisable UI component: Banner [#8276](https://github.com/opencrvs/opencrvs-core/issues/8276)

### Improvements

Expand Down
97 changes: 97 additions & 0 deletions packages/components/src/Banner/Banner.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import React from 'react'
import { Banner, IBannerProps } from './Banner'
import { Text } from '../Text'
import { Meta, StoryObj } from '@storybook/react'
import { Button } from '../Button'
import { Pill } from '../Pill'
import { Icon } from '../Icon'

const meta: Meta<IBannerProps> = {
title: 'Layout/Banner',
argTypes: {
type: {
control: {
type: 'radio',
options: ['active', 'inactive', 'pending', 'default']
}
}
},
render: (args) => (
<Banner.Container>
<Banner.Header type={args.type}>
<Text variant="reg16" element="span">
This is header
</Text>
</Banner.Header>
<Banner.Body>
<Text variant="reg16" element="span">
This is body
</Text>
</Banner.Body>
<Banner.Footer>
<Button type="primary">Click me</Button>
</Banner.Footer>
</Banner.Container>
)
}

export default meta

export const Default: StoryObj<IBannerProps> = {
args: {
type: 'default'
}
}

export const Active: StoryObj<IBannerProps> = {
args: {
type: 'active'
}
}

export const Pending: StoryObj<IBannerProps> = {
args: {
type: 'pending'
}
}

export const PendingAdvanced: StoryObj<IBannerProps> = {
render: () => (
<Banner.Container>
<Banner.Header type="pending">
<Pill
type="pending"
size="small"
pillTheme="dark"
label={
<>
<Icon name="QrCode" size="small" />
ID Pending Verification
</>
}
/>
<Icon name="Clock" size="large" />
</Banner.Header>
<Banner.Body>
<Text variant="reg16" element="span">
The Notifier’s identity has been verified successfully using the
National Identity system. To make edits, please remove the
verification first.
</Text>
</Banner.Body>
<Banner.Footer justifyContent="flex-end">
<Button type="secondary">Reset</Button>
</Banner.Footer>
</Banner.Container>
)
}
72 changes: 72 additions & 0 deletions packages/components/src/Banner/Banner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import React from 'react'
import { Box } from '../Box'
import { IStackProps, Stack } from '../Stack'
import styled from 'styled-components'

const Wrapper = styled(Box)`
padding: 0;
`
const HeaderWrapper = styled(Stack)<{
type: 'active' | 'inactive' | 'pending' | 'default'
}>`
padding: 8px 16px;
--background-color: ${({ type, theme }) => `
${type === 'active' ? theme.colors.greenLighter : ''}
${type === 'inactive' ? theme.colors.redLighter : ''}
${type === 'pending' ? theme.colors.orangeLighter : ''}
${type === 'default' ? theme.colors.primaryLighter : ''}
`};
--color: ${({ type, theme }) => `
${type === 'active' ? theme.colors.positiveDarker : ''}
${type === 'inactive' ? theme.colors.negativeDarker : ''}
${type === 'pending' ? theme.colors.neutralDarker : ''}
${type === 'default' ? theme.colors.primaryDarker : ''}
`};
background-color: var(--background-color);
color: var(--color);
`
const ContentWrapper = styled(Stack)`
padding: 16px;
`

export interface IBannerProps {
type: 'active' | 'inactive' | 'pending' | 'default'
}

const Container: React.FC<{ children: React.ReactNode }> = ({ children }) => (
<Wrapper>{children}</Wrapper>
)

const Header: React.FC<{ children: React.ReactNode } & IBannerProps> = ({
children,
type
}) => (
<HeaderWrapper justifyContent="space-between" type={type}>
{children}
</HeaderWrapper>
)

const Body: React.FC<{ children: React.ReactNode }> = ({ children }) => (
<ContentWrapper>{children}</ContentWrapper>
)

const Footer: React.FC<{ children: React.ReactNode } & IStackProps> = ({
children,
...otherProps
}) => (
<ContentWrapper direction="row" {...otherProps}>
{children}
</ContentWrapper>
)

export const Banner = { Container, Header, Body, Footer }
12 changes: 12 additions & 0 deletions packages/components/src/Banner/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

export * from './Banner'
4 changes: 3 additions & 1 deletion packages/components/src/Icon/all-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export {
PencilLine,
PencilCircle,
Handshake,
UserCircle
UserCircle,
Clock,
QrCode
} from 'phosphor-react'
export * from './custom-icons'
14 changes: 14 additions & 0 deletions packages/components/src/Pill/Pill.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,17 @@ Inactive.args = {
label: 'Inactive',
type: 'inactive'
}

export const ActiveDark = Template.bind({})
ActiveDark.args = {
label: 'Active Dark',
type: 'active',
pillTheme: 'dark'
}

export const PendingDark = Template.bind({})
PendingDark.args = {
label: 'Pending Dark',
type: 'pending',
pillTheme: 'dark'
}
28 changes: 23 additions & 5 deletions packages/components/src/Pill/Pill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ type IPillType = 'active' | 'inactive' | 'pending' | 'default'

type IPillSize = 'small' | 'medium'

type IPillTheme = 'light' | 'dark'

export interface IPillProps {
label: string
label: React.ReactNode
type?: IPillType
size?: IPillSize
pillTheme?: IPillTheme
}

const heightMap: Record<IPillSize, string> = {
Expand All @@ -32,21 +35,35 @@ const fontMap: Record<IPillSize, IFont> = {
medium: 'bold16'
}

const StyledPill = styled.span<{ size: IPillSize; type: IPillType }>`
--background-color: ${({ type, theme }) => `
const StyledPill = styled.span<{
size: IPillSize
type: IPillType
pillTheme: IPillTheme
}>`
--lighterShade: ${({ type, theme }) => `
${type === 'active' ? theme.colors.greenLighter : ''}
${type === 'inactive' ? theme.colors.redLighter : ''}
${type === 'pending' ? theme.colors.orangeLighter : ''}
${type === 'default' ? theme.colors.primaryLighter : ''}
`};

--color: ${({ type, theme }) => `
--darkerShade: ${({ type, theme }) => `
${type === 'active' ? theme.colors.positiveDarker : ''}
${type === 'inactive' ? theme.colors.negativeDarker : ''}
${type === 'pending' ? theme.colors.neutralDarker : ''}
${type === 'default' ? theme.colors.primaryDarker : ''}
`};

${({ pillTheme }) =>
pillTheme === 'dark'
? `
--color: var(--lighterShade);
--background-color: var(--darkerShade);
`
: `
--color: var(--darkerShade);
--background-color: var(--lighterShade);
`}
color: var(--color);
background: var(--background-color);
height: ${({ size }) => heightMap[size]};
Expand All @@ -61,10 +78,11 @@ export function Pill({
label,
type = 'default',
size = 'small',
pillTheme = 'light',
...rest
}: IPillProps) {
return (
<StyledPill type={type} size={size} {...rest}>
<StyledPill type={type} size={size} pillTheme={pillTheme} {...rest}>
{label}
</StyledPill>
)
Expand Down
Loading