From 548cff9ceedcb552bc8e771bee7459a69ec20eb0 Mon Sep 17 00:00:00 2001
From: = <=>
Date: Fri, 1 Dec 2023 09:58:31 +0530
Subject: [PATCH 1/7] add more colors in text component
---
.../src/components/Text/Text.module.scss | 22 ++++++--
.../src/components/Text/Text.stories.tsx | 54 ++++++++++++++-----
packages/opub-ui/src/types/text.ts | 14 +++--
3 files changed, 66 insertions(+), 24 deletions(-)
diff --git a/packages/opub-ui/src/components/Text/Text.module.scss b/packages/opub-ui/src/components/Text/Text.module.scss
index f7b93283..96bbe3f4 100644
--- a/packages/opub-ui/src/components/Text/Text.module.scss
+++ b/packages/opub-ui/src/components/Text/Text.module.scss
@@ -36,14 +36,14 @@
text-align: justify;
}
-.default {
- color: var(--text-default);
-}
-
.inherit {
color: inherit;
}
+.default {
+ color: var(--text-default);
+}
+
.disabled {
color: var(--text-disabled);
}
@@ -64,10 +64,22 @@
color: var(--text-subdued);
}
-.text-inverse {
+.highlight {
+ color: var(--text-highlight);
+}
+
+.interactive {
+ color: var(--text-interactive);
+}
+
+.onBgDefault {
color: var(--text-onbg-default);
}
+.onBgDisabled {
+ color: var(--text-onbg-disabled);
+}
+
.regular {
font-weight: 400;
}
diff --git a/packages/opub-ui/src/components/Text/Text.stories.tsx b/packages/opub-ui/src/components/Text/Text.stories.tsx
index a3c1fadf..9ebcd904 100644
--- a/packages/opub-ui/src/components/Text/Text.stories.tsx
+++ b/packages/opub-ui/src/components/Text/Text.stories.tsx
@@ -40,6 +40,9 @@ export const Variants = () => (
Text with HeadingXs variant
+
+ Text with headingSmSpaced variant
+
Text with BodyLg variant
@@ -91,30 +94,53 @@ export const WithFontWeight = () => (
);
export const WithColor = () => (
-
+
+
+ Default Text is used to communicate the majority of information on the
+
- Use to de-emphasize a piece of text that is less important to merchants
- than other nearby text. May also be used to indicate when normal content
- is absent, for example, “No supplier listed”. Don’t use only for aesthetic
- effect.
+ Subdued Text is used to create a hierarchy of information on the page.
+
+
+ Disabled Text is used to indicate that a field is disabled and cannot be
+ interacted with.
- Use in combination with a symbol showing an increasing value to indicate
- an upward trend.
+ Use to indicate that something was successful.
- Use to denote something that needs attention, or that merchants need to
- take action on.
+ Use to indicate that something needs attention.
- Use in combination with a symbol showing a decreasing value to indicate a
- downward trend.
-
-
-
+ Use to indicate that something has failed.
+
+
+ Highlight Text is used to highlight important information on the page.
+
+
+ Interactive Text is used to indicate that something can be interacted
+ with.
+
+
+
Use in situations where background is dark.
+
+
+ This is the disabled version for dark background
+
+
);
diff --git a/packages/opub-ui/src/types/text.ts b/packages/opub-ui/src/types/text.ts
index 914c4a83..a3ac9b76 100644
--- a/packages/opub-ui/src/types/text.ts
+++ b/packages/opub-ui/src/types/text.ts
@@ -30,13 +30,17 @@ type Alignment = 'start' | 'center' | 'end' | 'justify';
type FontWeight = 'regular' | 'medium' | 'semibold' | 'bold';
type Color =
- | 'success'
- | 'critical'
- | 'warning'
+ | 'default'
+ | 'medium'
| 'subdued'
- | 'text-inverse'
| 'disabled'
- | 'default'
+ | 'critical'
+ | 'warning'
+ | 'success'
+ | 'highlight'
+ | 'interactive'
+ | 'onBgDefault'
+ | 'onBgDisabled'
| 'inherit';
export const VariantFontWeightMapping: { [V in Variant]: FontWeight } = {
From ad0923c693aa3f3fc4b226386b8538d339d25ddc Mon Sep 17 00:00:00 2001
From: = <=>
Date: Fri, 1 Dec 2023 10:33:32 +0530
Subject: [PATCH 2/7] add Selector Card component
---
packages/opub-ui/src/components/Pill/Pill.tsx | 9 +++-
.../SelectorCard/SelectorCard.module.scss | 19 +++++++
.../SelectorCard/SelectorCard.stories.tsx | 54 +++++++++++++++++++
.../SelectorCard/SelectorCard.test.tsx | 13 +++++
.../components/SelectorCard/SelectorCard.tsx | 43 +++++++++++++++
.../src/components/SelectorCard/index.ts | 1 +
packages/opub-ui/src/components/index.ts | 1 +
packages/opub-ui/src/types/pill.ts | 2 +
8 files changed, 140 insertions(+), 2 deletions(-)
create mode 100644 packages/opub-ui/src/components/SelectorCard/SelectorCard.module.scss
create mode 100644 packages/opub-ui/src/components/SelectorCard/SelectorCard.stories.tsx
create mode 100644 packages/opub-ui/src/components/SelectorCard/SelectorCard.test.tsx
create mode 100644 packages/opub-ui/src/components/SelectorCard/SelectorCard.tsx
create mode 100644 packages/opub-ui/src/components/SelectorCard/index.ts
diff --git a/packages/opub-ui/src/components/Pill/Pill.tsx b/packages/opub-ui/src/components/Pill/Pill.tsx
index 3991bac2..f6c32b87 100644
--- a/packages/opub-ui/src/components/Pill/Pill.tsx
+++ b/packages/opub-ui/src/components/Pill/Pill.tsx
@@ -18,6 +18,7 @@ export const Pill = React.forwardRef(
url,
returnValue = '',
variant = 'neutral',
+ truncate,
...other
}: PillProps,
ref: React.LegacyRef
@@ -54,10 +55,14 @@ export const Pill = React.forwardRef(
const tagContent =
url && !disabled ? (
- {children}
+
+ {children}
+
) : (
- {children}
+
+ {children}
+
);
return (
diff --git a/packages/opub-ui/src/components/SelectorCard/SelectorCard.module.scss b/packages/opub-ui/src/components/SelectorCard/SelectorCard.module.scss
new file mode 100644
index 00000000..43f7fb57
--- /dev/null
+++ b/packages/opub-ui/src/components/SelectorCard/SelectorCard.module.scss
@@ -0,0 +1,19 @@
+@import '../../../styles/common';
+
+.SelectorCard {
+ display: flex;
+ flex-direction: column;
+ gap: var(--space-2);
+ padding: var(--space-3, 12px);
+ max-width: 480px;
+ width: 100%;
+ border-radius: var(--border-radius-05, 2px);
+ background: var(--surface-default, #fff);
+ box-shadow: var(--shadow-element-card);
+}
+
+.PillWrapper {
+ display: flex;
+ flex-direction: column;
+ gap: var(--space-2);
+}
diff --git a/packages/opub-ui/src/components/SelectorCard/SelectorCard.stories.tsx b/packages/opub-ui/src/components/SelectorCard/SelectorCard.stories.tsx
new file mode 100644
index 00000000..54d189c6
--- /dev/null
+++ b/packages/opub-ui/src/components/SelectorCard/SelectorCard.stories.tsx
@@ -0,0 +1,54 @@
+import { Pill } from '../Pill';
+import { SelectorCard } from './SelectorCard';
+import { Meta, StoryObj } from '@storybook/react';
+
+/**
+ * Selector Card is a component that displays a title, a selected value, and a button.
+ */
+const meta = {
+ component: SelectorCard,
+} satisfies Meta;
+
+export default meta;
+type Story = StoryObj;
+
+export const Default: Story = {
+ args: {
+ title: 'SelectorCard',
+ selected:
+ 'Person Days Generated as a share of Cumulative Projection of Person Days',
+ buttonText: 'Switch Indicator',
+ onClick: () => {},
+ },
+};
+
+export const Pills: Story = {
+ args: {
+ title: 'SelectorCard',
+ selected: (
+ <>
+ {
+ console.log(e);
+ }}
+ returnValue="1"
+ >
+ Person Days Generated as a share of Cumulative Projection of Person
+ Days
+
+ {}} returnValue="2">
+ Person Days Generated as a share of Cumulative Projection of Person
+ Days
+
+ {}} returnValue="3">
+ Person Days Generated as a share of Cumulative Projection of Person
+ Days
+
+ >
+ ),
+ buttonText: 'Edit Indicators',
+ onClick: () => {},
+ },
+};
diff --git a/packages/opub-ui/src/components/SelectorCard/SelectorCard.test.tsx b/packages/opub-ui/src/components/SelectorCard/SelectorCard.test.tsx
new file mode 100644
index 00000000..caceeedb
--- /dev/null
+++ b/packages/opub-ui/src/components/SelectorCard/SelectorCard.test.tsx
@@ -0,0 +1,13 @@
+import "@testing-library/jest-dom";
+import { render, screen } from "@testing-library/react";
+import { SelectorCard } from "./SelectorCard";
+
+describe("SelectorCard Tests", () => {
+ beforeEach(() => {
+ render(Component);
+ });
+
+ test("should show Component text all the time", () => {
+ expect(screen.getByText(/Component/i)).toBeInTheDocument();
+ });
+});
diff --git a/packages/opub-ui/src/components/SelectorCard/SelectorCard.tsx b/packages/opub-ui/src/components/SelectorCard/SelectorCard.tsx
new file mode 100644
index 00000000..71743a3d
--- /dev/null
+++ b/packages/opub-ui/src/components/SelectorCard/SelectorCard.tsx
@@ -0,0 +1,43 @@
+import { cn } from '../../utils';
+import { Button } from '../Button';
+import { Divider } from '../Divider';
+import { Pill } from '../Pill';
+import { Text } from '../Text';
+import styles from './SelectorCard.module.scss';
+import React, { forwardRef } from 'react';
+
+type Props = {
+ title: string;
+ selected: string | React.ReactNode;
+ buttonText: string;
+ onClick: () => void;
+};
+
+const SelectorCard = forwardRef((props: Props, ref: any) => {
+ const { title, selected, buttonText, onClick } = props;
+ const themeClass = cn(styles.SelectorCard);
+
+ let content;
+ if (typeof selected === 'string') {
+ content = (
+
+ Person Days Generated as a share of Cumulative Projection of Person Days
+
+ );
+ } else {
+ content =
{selected}
;
+ }
+
+ return (
+
+ {title}
+ {content}
+
+
+
+ );
+});
+
+export { SelectorCard };
diff --git a/packages/opub-ui/src/components/SelectorCard/index.ts b/packages/opub-ui/src/components/SelectorCard/index.ts
new file mode 100644
index 00000000..7e0fda19
--- /dev/null
+++ b/packages/opub-ui/src/components/SelectorCard/index.ts
@@ -0,0 +1 @@
+export { SelectorCard } from "./SelectorCard";
diff --git a/packages/opub-ui/src/components/index.ts b/packages/opub-ui/src/components/index.ts
index 8e904238..d4c3f475 100644
--- a/packages/opub-ui/src/components/index.ts
+++ b/packages/opub-ui/src/components/index.ts
@@ -60,3 +60,4 @@ export { Toast, Toaster, useToast } from './Toast';
export { Tooltip } from './Tooltip';
export { SearchInput } from "./SearchInput";
export { Tray } from "./Tray";
+export { SelectorCard } from "./SelectorCard";
diff --git a/packages/opub-ui/src/types/pill.ts b/packages/opub-ui/src/types/pill.ts
index 453030a9..5f5b2213 100644
--- a/packages/opub-ui/src/types/pill.ts
+++ b/packages/opub-ui/src/types/pill.ts
@@ -11,6 +11,8 @@ interface NonMutuallyExclusiveProps {
variant?: 'neutral' | 'info' | 'success' | 'warning' | 'critical';
/** Value that is returned on click of remove button */
returnValue?: string;
+ /** Truncate text to one line */
+ truncate?: boolean;
}
export type PillProps = NonMutuallyExclusiveProps &
From 809ab2ea3ba7f9b004c1c2f9ece32461c04182fa Mon Sep 17 00:00:00 2001
From: = <=>
Date: Fri, 1 Dec 2023 11:08:55 +0530
Subject: [PATCH 3/7] add district switcher for homepage
---
.../components/district-selector-mobile.tsx | 126 ++++++++++++++++++
.../[locale]/components/district-selector.tsx | 4 +-
.../district/app/[locale]/components/index.ts | 1 +
.../app/[locale]/components/quick-links.tsx | 5 +-
examples/district/app/[locale]/page.tsx | 2 +
examples/district/components/icons.tsx | 3 +-
.../components/SearchInput/SearchInput.tsx | 2 +-
.../components/SelectorCard/SelectorCard.tsx | 1 -
8 files changed, 136 insertions(+), 8 deletions(-)
create mode 100644 examples/district/app/[locale]/components/district-selector-mobile.tsx
diff --git a/examples/district/app/[locale]/components/district-selector-mobile.tsx b/examples/district/app/[locale]/components/district-selector-mobile.tsx
new file mode 100644
index 00000000..a1defe73
--- /dev/null
+++ b/examples/district/app/[locale]/components/district-selector-mobile.tsx
@@ -0,0 +1,126 @@
+import { Button, Divider, Icon, SearchInput, Text, Tray } from 'opub-ui';
+import {
+ assamDistrictCategory,
+ availableDistricts,
+ filterDistricts,
+} from '../home.config';
+import { cn } from '@/lib/utils';
+import Link from 'next/link';
+import Icons from '@/components/icons';
+import React from 'react';
+
+export const DistrictSelectorMobile = () => {
+ const [search, setSearch] = React.useState('');
+ const [districtList, setDistrictList] = React.useState(assamDistrictCategory);
+
+ // filter districtList based on search
+ React.useEffect(() => {
+ if (search) {
+ const filteredDistricts = filterDistricts(search.toLowerCase());
+ setDistrictList(filteredDistricts);
+ } else {
+ setDistrictList(assamDistrictCategory);
+ }
+ }, [search]);
+
+ return (
+
+
+
+ Districts
+
+
+ Select district to view insights
+
+
+