Skip to content

Commit f5a62ad

Browse files
committed
feat: move segmented control from fe-lib
1 parent c2a4b49 commit f5a62ad

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2024. Devtron Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { OptionType } from '@Common/Types'
18+
import StyledRadioGroup from '../RadioGroup/RadioGroup'
19+
import { SegmentedControlProps } from './types'
20+
21+
const SegmentedControl = ({
22+
tabs,
23+
initialTab,
24+
onChange,
25+
tooltips,
26+
disabled = false,
27+
rootClassName = '',
28+
}: SegmentedControlProps) => (
29+
<StyledRadioGroup
30+
className={`gui-yaml-switch-window-bg ${rootClassName}`}
31+
onChange={onChange}
32+
initialTab={initialTab}
33+
name="segmented-control"
34+
disabled={disabled}
35+
>
36+
{tabs.map((tab: OptionType, index) => (
37+
<StyledRadioGroup.Radio
38+
value={tab.value}
39+
key={tab.value}
40+
className="fs-12 cn-7 fw-6 lh-20"
41+
showTippy={!!tooltips?.[index]}
42+
tippyContent={tooltips?.[index] ?? ''}
43+
>
44+
{tab.label}
45+
</StyledRadioGroup.Radio>
46+
))}
47+
</StyledRadioGroup>
48+
)
49+
50+
export default SegmentedControl

src/Common/SegmentedControl/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export type { SegmentedControlProps } from './types'
2+
export { default as SegmentedControl } from './SegmentedControl.component'

src/Common/SegmentedControl/types.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2024. Devtron Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { OptionType } from '@Common/Types'
18+
19+
export interface SegmentedControlProps {
20+
tabs: OptionType[]
21+
initialTab: string
22+
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void
23+
tooltips?: string[]
24+
disabled?: boolean
25+
rootClassName?: string
26+
}

src/Common/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ export * from './SegmentedBarChart'
7070
export * from './CodeEditor'
7171
export * from './AppStatus'
7272
export * from './Tooltip'
73+
export * from './SegmentedControl'

src/Shared/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,11 @@ export enum ConfigurationType {
686686
YAML = 'YAML',
687687
}
688688

689+
export const CONFIGURATION_TYPE_OPTIONS: OptionType<ConfigurationType, ConfigurationType>[] = [
690+
{ label: ConfigurationType.GUI, value: ConfigurationType.GUI },
691+
{ label: ConfigurationType.YAML, value: ConfigurationType.YAML },
692+
] as const
693+
689694
export interface BaseURLParams {
690695
appId: string
691696
envId: string

0 commit comments

Comments
 (0)