@delightui/components 0.1.110 → 0.1.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/molecules/Modal/Modal.types.d.ts +5 -0
- package/dist/cjs/components/molecules/Search/Search.d.ts +18 -0
- package/dist/cjs/components/molecules/Search/Search.presenter.d.ts +320 -0
- package/dist/cjs/components/molecules/Search/Search.types.d.ts +53 -0
- package/dist/cjs/components/molecules/Search/index.d.ts +2 -0
- package/dist/cjs/components/molecules/index.d.ts +2 -0
- package/dist/cjs/components/organisms/SlideOutPanel/FadeTransition.d.ts +8 -0
- package/dist/cjs/components/utils/RenderStateView/RenderStateView.types.d.ts +4 -0
- package/dist/cjs/components/utils/RenderStateView/usePresenter.d.ts +1 -0
- package/dist/cjs/components/utils/index.d.ts +2 -0
- package/dist/cjs/components/utils/useDebounce/index.d.ts +1 -0
- package/dist/cjs/components/utils/useDebounce/useDebounce.d.ts +10 -0
- package/dist/cjs/library.css +1699 -23
- package/dist/cjs/library.js +3 -3
- package/dist/cjs/library.js.map +1 -1
- package/dist/esm/components/molecules/Modal/Modal.types.d.ts +5 -0
- package/dist/esm/components/molecules/Search/Search.d.ts +18 -0
- package/dist/esm/components/molecules/Search/Search.presenter.d.ts +320 -0
- package/dist/esm/components/molecules/Search/Search.types.d.ts +53 -0
- package/dist/esm/components/molecules/Search/index.d.ts +2 -0
- package/dist/esm/components/molecules/index.d.ts +2 -0
- package/dist/esm/components/organisms/SlideOutPanel/FadeTransition.d.ts +8 -0
- package/dist/esm/components/utils/RenderStateView/RenderStateView.types.d.ts +4 -0
- package/dist/esm/components/utils/RenderStateView/usePresenter.d.ts +1 -0
- package/dist/esm/components/utils/index.d.ts +2 -0
- package/dist/esm/components/utils/useDebounce/index.d.ts +1 -0
- package/dist/esm/components/utils/useDebounce/useDebounce.d.ts +10 -0
- package/dist/esm/library.css +1699 -23
- package/dist/esm/library.js +3 -3
- package/dist/esm/library.js.map +1 -1
- package/dist/index.d.ts +91 -1
- package/docs/README.md +6 -0
- package/docs/components/atoms/Input.md +0 -63
- package/docs/components/molecules/Search.md +710 -0
- package/docs/components/utils/RenderStateView.md +138 -39
- package/docs/components/utils/useDebounce.md +576 -0
- package/package.json +4 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Description
|
|
4
4
|
|
|
5
|
-
A utility component that manages different rendering states for data-driven components. RenderStateView provides a clean way to handle loading, empty, and filled states with customizable components for each state, making it perfect for data fetching scenarios where you need to display different content based on the presence and
|
|
5
|
+
A utility component that manages different rendering states for data-driven components. RenderStateView provides a clean way to handle error, loading, empty, and filled states with customizable components for each state, making it perfect for data fetching scenarios where you need to display different content based on the presence, loading state, and error state of data.
|
|
6
6
|
|
|
7
7
|
## Aliases
|
|
8
8
|
|
|
@@ -18,11 +18,13 @@ A utility component that manages different rendering states for data-driven comp
|
|
|
18
18
|
| Prop | Type | Default | Required | Description |
|
|
19
19
|
|------|------|---------|----------|-------------|
|
|
20
20
|
| `className` | `string` | - | No | Additional CSS class names |
|
|
21
|
-
| `data` | `T \| null` | - | No | The data to render
|
|
21
|
+
| `data` | `T \| null` | - | No | The data to render. If the data is null, the empty component will be rendered. If the data is not null, the filled component will be rendered. |
|
|
22
22
|
| `isLoading` | `boolean` | - | No | Whether data is currently loading |
|
|
23
|
+
| `errorData` | `Error \| string \| null` | - | No | Error data to trigger error state rendering |
|
|
23
24
|
| `filled` | `React.ComponentType<{ data: T } & P>` | - | No | Component to render when data is present |
|
|
24
25
|
| `empty` | `React.ComponentType<P>` | - | No | Component to render when no data |
|
|
25
26
|
| `loading` | `React.ComponentType<P>` | - | No | Component to render during loading state |
|
|
27
|
+
| `error` | `React.ComponentType<{ error: Error \| string } & P>` | - | No | Component to render when error occurs |
|
|
26
28
|
|
|
27
29
|
This component does not add standard HTML attributes as it renders different components based on state.
|
|
28
30
|
|
|
@@ -88,7 +90,7 @@ function BasicRenderStateExample() {
|
|
|
88
90
|
</Button>
|
|
89
91
|
|
|
90
92
|
<RenderStateView
|
|
91
|
-
data={users
|
|
93
|
+
data={users}
|
|
92
94
|
isLoading={isLoading}
|
|
93
95
|
loading={LoadingComponent}
|
|
94
96
|
empty={EmptyComponent}
|
|
@@ -191,7 +193,7 @@ function ProductCatalogExample() {
|
|
|
191
193
|
/>
|
|
192
194
|
|
|
193
195
|
<RenderStateView
|
|
194
|
-
data={products
|
|
196
|
+
data={products}
|
|
195
197
|
isLoading={isLoading}
|
|
196
198
|
loading={LoadingSpinner}
|
|
197
199
|
empty={EmptyState}
|
|
@@ -539,7 +541,7 @@ function ShoppingCartExample() {
|
|
|
539
541
|
return (
|
|
540
542
|
<div style={{ padding: '20px', maxWidth: '600px' }}>
|
|
541
543
|
<RenderStateView
|
|
542
|
-
data={cartItems
|
|
544
|
+
data={cartItems}
|
|
543
545
|
isLoading={isLoading}
|
|
544
546
|
loading={CartLoading}
|
|
545
547
|
empty={EmptyCart}
|
|
@@ -626,7 +628,7 @@ function FileUploadManagerExample() {
|
|
|
626
628
|
</Text>
|
|
627
629
|
|
|
628
630
|
<RenderStateView
|
|
629
|
-
data={files
|
|
631
|
+
data={files}
|
|
630
632
|
isLoading={isLoading}
|
|
631
633
|
loading={UploadingState}
|
|
632
634
|
empty={NoFilesState}
|
|
@@ -637,28 +639,29 @@ function FileUploadManagerExample() {
|
|
|
637
639
|
}
|
|
638
640
|
```
|
|
639
641
|
|
|
640
|
-
###
|
|
642
|
+
### Error State Handling
|
|
641
643
|
|
|
642
644
|
```tsx
|
|
643
645
|
import { RenderStateView, Text, Button, Card } from '@delightui/components';
|
|
644
646
|
|
|
645
|
-
function
|
|
647
|
+
function ErrorStateExample() {
|
|
646
648
|
const [data, setData] = useState<any>(null);
|
|
647
649
|
const [isLoading, setIsLoading] = useState(false);
|
|
648
|
-
const [
|
|
650
|
+
const [errorData, setErrorData] = useState<Error | string | null>(null);
|
|
649
651
|
|
|
650
652
|
const fetchData = async (shouldFail = false) => {
|
|
651
653
|
setIsLoading(true);
|
|
652
|
-
|
|
654
|
+
setErrorData(null);
|
|
655
|
+
setData(null);
|
|
656
|
+
|
|
653
657
|
try {
|
|
654
658
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
655
659
|
if (shouldFail) {
|
|
656
|
-
throw new Error('Network
|
|
660
|
+
throw new Error('Network connection failed');
|
|
657
661
|
}
|
|
658
|
-
setData({ message: 'Data loaded successfully!' });
|
|
662
|
+
setData({ message: 'Data loaded successfully!', timestamp: new Date().toISOString() });
|
|
659
663
|
} catch (err) {
|
|
660
|
-
|
|
661
|
-
setData(null);
|
|
664
|
+
setErrorData(err instanceof Error ? err : 'Unknown error occurred');
|
|
662
665
|
} finally {
|
|
663
666
|
setIsLoading(false);
|
|
664
667
|
}
|
|
@@ -670,56 +673,152 @@ function CustomErrorStatesExample() {
|
|
|
670
673
|
</Card>
|
|
671
674
|
);
|
|
672
675
|
|
|
673
|
-
const ErrorComponent = () => (
|
|
676
|
+
const ErrorComponent = ({ error }: { error: Error | string }) => (
|
|
674
677
|
<Card style={{ padding: '40px', textAlign: 'center', backgroundColor: '#ffebee' }}>
|
|
675
678
|
<Text size="large">❌ Error Occurred</Text>
|
|
676
|
-
<Text>{error}</Text>
|
|
679
|
+
<Text>{typeof error === 'string' ? error : error.message}</Text>
|
|
677
680
|
<div style={{ marginTop: '20px', display: 'flex', gap: '12px', justifyContent: 'center' }}>
|
|
678
681
|
<Button onClick={() => fetchData(false)}>Retry</Button>
|
|
679
|
-
<Button type="Outlined" onClick={() =>
|
|
682
|
+
<Button type="Outlined" onClick={() => setErrorData(null)}>Dismiss</Button>
|
|
680
683
|
</div>
|
|
681
684
|
</Card>
|
|
682
685
|
);
|
|
683
686
|
|
|
687
|
+
const EmptyComponent = () => (
|
|
688
|
+
<Card style={{ padding: '40px', textAlign: 'center' }}>
|
|
689
|
+
<Text>📭 No data available</Text>
|
|
690
|
+
<Button onClick={() => fetchData(false)} style={{ marginTop: '16px' }}>
|
|
691
|
+
Load Data
|
|
692
|
+
</Button>
|
|
693
|
+
</Card>
|
|
694
|
+
);
|
|
695
|
+
|
|
684
696
|
const SuccessComponent = ({ data }: { data: any }) => (
|
|
685
697
|
<Card style={{ padding: '40px', textAlign: 'center', backgroundColor: '#e8f5e8' }}>
|
|
686
698
|
<Text size="large">✅ Success!</Text>
|
|
687
699
|
<Text>{data.message}</Text>
|
|
700
|
+
<Text size="small">Loaded at: {data.timestamp}</Text>
|
|
688
701
|
</Card>
|
|
689
702
|
);
|
|
690
703
|
|
|
691
|
-
// Use error state to determine what to show
|
|
692
|
-
const currentData = error ? null : data;
|
|
693
|
-
|
|
694
704
|
return (
|
|
695
705
|
<div style={{ padding: '20px', maxWidth: '400px' }}>
|
|
696
706
|
<Text size="xl" weight="Bold" style={{ marginBottom: '20px' }}>
|
|
697
|
-
Error
|
|
707
|
+
Error State Demo
|
|
698
708
|
</Text>
|
|
699
709
|
|
|
700
710
|
<div style={{ marginBottom: '20px', display: 'flex', gap: '12px' }}>
|
|
701
711
|
<Button onClick={() => fetchData(false)}>Load Success</Button>
|
|
702
712
|
<Button onClick={() => fetchData(true)}>Trigger Error</Button>
|
|
713
|
+
<Button type="Outlined" onClick={() => { setData(null); setErrorData(null); }}>
|
|
714
|
+
Reset
|
|
715
|
+
</Button>
|
|
703
716
|
</div>
|
|
704
717
|
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
718
|
+
<RenderStateView
|
|
719
|
+
data={data}
|
|
720
|
+
isLoading={isLoading}
|
|
721
|
+
errorData={errorData}
|
|
722
|
+
loading={LoadingComponent}
|
|
723
|
+
error={ErrorComponent}
|
|
724
|
+
empty={EmptyComponent}
|
|
725
|
+
filled={SuccessComponent}
|
|
726
|
+
/>
|
|
727
|
+
</div>
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
### API Error Handling
|
|
733
|
+
|
|
734
|
+
```tsx
|
|
735
|
+
import { RenderStateView, Text, Button, Card } from '@delightui/components';
|
|
736
|
+
|
|
737
|
+
function ApiErrorExample() {
|
|
738
|
+
const [users, setUsers] = useState<any[]>([]);
|
|
739
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
740
|
+
const [apiError, setApiError] = useState<Error | null>(null);
|
|
741
|
+
|
|
742
|
+
const fetchUsers = async () => {
|
|
743
|
+
setIsLoading(true);
|
|
744
|
+
setApiError(null);
|
|
745
|
+
|
|
746
|
+
try {
|
|
747
|
+
const response = await fetch('/api/users');
|
|
748
|
+
if (!response.ok) {
|
|
749
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
750
|
+
}
|
|
751
|
+
const userData = await response.json();
|
|
752
|
+
setUsers(userData);
|
|
753
|
+
} catch (err) {
|
|
754
|
+
setApiError(err instanceof Error ? err : new Error('Network request failed'));
|
|
755
|
+
setUsers([]);
|
|
756
|
+
} finally {
|
|
757
|
+
setIsLoading(false);
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
const LoadingUsers = () => (
|
|
762
|
+
<Card style={{ padding: '30px', textAlign: 'center' }}>
|
|
763
|
+
<Text>👥 Loading users...</Text>
|
|
764
|
+
</Card>
|
|
765
|
+
);
|
|
766
|
+
|
|
767
|
+
const ApiErrorDisplay = ({ error }: { error: Error }) => (
|
|
768
|
+
<Card style={{ padding: '30px', textAlign: 'center', backgroundColor: '#fff3e0' }}>
|
|
769
|
+
<Text size="large">⚠️ API Error</Text>
|
|
770
|
+
<Text>{error.message}</Text>
|
|
771
|
+
<Text size="small" style={{ marginTop: '8px' }}>
|
|
772
|
+
Please check your network connection and try again
|
|
773
|
+
</Text>
|
|
774
|
+
<Button onClick={fetchUsers} style={{ marginTop: '16px' }}>
|
|
775
|
+
Retry Request
|
|
776
|
+
</Button>
|
|
777
|
+
</Card>
|
|
778
|
+
);
|
|
779
|
+
|
|
780
|
+
const NoUsers = () => (
|
|
781
|
+
<Card style={{ padding: '30px', textAlign: 'center' }}>
|
|
782
|
+
<Text>👤 No users found</Text>
|
|
783
|
+
<Button onClick={fetchUsers} style={{ marginTop: '16px' }}>
|
|
784
|
+
Load Users
|
|
785
|
+
</Button>
|
|
786
|
+
</Card>
|
|
787
|
+
);
|
|
788
|
+
|
|
789
|
+
const UsersList = ({ data }: { data: any[] }) => (
|
|
790
|
+
<div>
|
|
791
|
+
<Text weight="Bold" style={{ marginBottom: '16px' }}>
|
|
792
|
+
Users ({data.length})
|
|
793
|
+
</Text>
|
|
794
|
+
{data.map(user => (
|
|
795
|
+
<Card key={user.id} style={{ padding: '16px', marginBottom: '8px' }}>
|
|
796
|
+
<Text weight="Bold">{user.name}</Text>
|
|
797
|
+
<Text size="small">{user.email}</Text>
|
|
798
|
+
</Card>
|
|
799
|
+
))}
|
|
800
|
+
</div>
|
|
801
|
+
);
|
|
802
|
+
|
|
803
|
+
return (
|
|
804
|
+
<div style={{ padding: '20px', maxWidth: '500px' }}>
|
|
805
|
+
<Text size="xl" weight="Bold" style={{ marginBottom: '20px' }}>
|
|
806
|
+
API Error Handling
|
|
807
|
+
</Text>
|
|
808
|
+
|
|
809
|
+
<Button onClick={fetchUsers} disabled={isLoading} style={{ marginBottom: '20px' }}>
|
|
810
|
+
Fetch Users
|
|
811
|
+
</Button>
|
|
812
|
+
|
|
813
|
+
<RenderStateView
|
|
814
|
+
data={users}
|
|
815
|
+
isLoading={isLoading}
|
|
816
|
+
errorData={apiError}
|
|
817
|
+
loading={LoadingUsers}
|
|
818
|
+
error={ApiErrorDisplay}
|
|
819
|
+
empty={NoUsers}
|
|
820
|
+
filled={UsersList}
|
|
821
|
+
/>
|
|
723
822
|
</div>
|
|
724
823
|
);
|
|
725
824
|
}
|