-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
129 lines (115 loc) · 3.25 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import featureFlags, {
CookiesChannel,
QueryParamsClientChannel,
CustomEventChannel,
useFeatureFlag,
} from "react-modular-feature-flags";
import Logo from "./assets/logo.svg?react";
import MyCustomChannel from "./my-custom-channel.class";
enum Flags {
default = "default",
foo = "foo",
bar = "bar",
baz = "baz",
}
// Initialize the feature flags
featureFlags.init({
defaultFeatureFlags: { [Flags.default]: true },
});
// Initialize the cookies channel
featureFlags.initChannel({ priority: 1 }, new CookiesChannel());
// Initialize the query params client channel
featureFlags.initChannel({ priority: 2 }, new QueryParamsClientChannel());
// Initialize the custom event channel
featureFlags.initChannel({ priority: 3 }, new CustomEventChannel());
// Initialize custom channel
featureFlags.initChannel(
{ priority: 4 },
new MyCustomChannel({ key: Flags.baz, delay: 2000 })
);
function App() {
return (
<div className="container mx-auto">
<div className="py-12 w-2/5">
<h1>
<Logo />
</h1>
</div>
<Alert />
<div className="relative overflow-x-auto">
<table className="w-full text-sm text-left rtl:text-right text-gray-500 ">
<thead className="text-xs text-gray-700 uppercase bg-gray-50">
<tr>
<th scope="col" className="px-6 py-3">
Feature Flag Key
</th>
<th scope="col" className="px-6 py-3">
Status
</th>
</tr>
</thead>
<tbody>
<ItemFlag flagKey={Flags.default} />
<ItemFlag flagKey={Flags.foo} />
<ItemFlag flagKey={Flags.bar} />
<ItemFlag flagKey={Flags.baz} />
</tbody>
</table>
</div>
</div>
);
}
function ItemFlag({ flagKey }: { flagKey: string }) {
const flagValue = useFeatureFlag(flagKey);
return (
<tr>
<th scope="col" className="px-6 py-3">
{flagKey}
</th>
<th scope="col" className="px-6 py-3">
{flagValue ? <BadgeActive /> : <BadgeInactive />}
</th>
</tr>
);
}
function BadgeActive() {
return (
<span className="bg-green-100 text-green-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded">
Active
</span>
);
}
function BadgeInactive() {
return (
<span className="bg-red-100 text-red-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded">
Inactive
</span>
);
}
function Alert() {
return (
<div
className="flex items-center p-4 mb-4 text-sm text-sky-800 rounded-lg bg-sky-50"
role="alert"
>
<svg
className="flex-shrink-0 inline w-4 h-4 me-3"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
viewBox="0 0 20 20"
>
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z" />
</svg>
<span className="sr-only">Info</span>
<div>
Access the{" "}
<a href="#as" className="underline underline-offset-4">
documentation
</a>{" "}
to learn how to enable and disable feature flags.
</div>
</div>
);
}
export default App;