|
| 1 | +import React, { FC, useState, useContext } from 'react'; |
| 2 | +import cn from 'classnames'; |
| 3 | + |
| 4 | +import { useTextStyles, createTextCn } from '@rescui/typography'; |
| 5 | +import { TabList, Tab } from '@rescui/tab-list'; |
| 6 | +import { Button } from '@rescui/button'; |
| 7 | +import { ThemeProvider } from '@rescui/ui-contexts'; |
| 8 | +import { CodeIcon, PlayIcon } from '@rescui/icons'; |
| 9 | + |
| 10 | +import '@jetbrains/kotlin-web-site-ui/out/components/layout'; |
| 11 | + |
| 12 | +import { CodeBlock } from '../../../components/code-block/code-block'; |
| 13 | + |
| 14 | +import styles from './why-kotlin.module.css'; |
| 15 | +import './playground.css'; |
| 16 | + |
| 17 | +import { CodeBlockContext } from '../../../components/code-block/code-block'; |
| 18 | + |
| 19 | +import simpleExample from './code-examples/simple.md'; |
| 20 | +import asyncExample from './code-examples/asynchronous.md'; |
| 21 | +import oopExample from './code-examples/object-oriented.md'; |
| 22 | +import functionalExample from './code-examples/functional.md'; |
| 23 | +import testsExample from './code-examples/ideal-for-tests.md'; |
| 24 | + |
| 25 | +interface Props {} |
| 26 | + |
| 27 | +const ContentSwitcher = ({ index, children }) => { |
| 28 | + return children[index]; |
| 29 | +}; |
| 30 | + |
| 31 | +export const WhyKotlin: FC<Props> = ({}) => { |
| 32 | + const [activeIndex, setActiveIndex] = useState(0); |
| 33 | + |
| 34 | + const textCn = useTextStyles(); |
| 35 | + const darkTextCn = createTextCn('dark'); |
| 36 | + |
| 37 | + const codeBlockInstance = useContext(CodeBlockContext); |
| 38 | + |
| 39 | + const handleRunButton = () => { |
| 40 | + codeBlockInstance.execute(); |
| 41 | + }; |
| 42 | + |
| 43 | + return ( |
| 44 | + <ThemeProvider theme={'dark'}> |
| 45 | + <section className={styles.whyKotlin}> |
| 46 | + <div className={cn('ktl-layout', 'ktl-layout--center')}> |
| 47 | + <div className={cn(darkTextCn('rs-h1'), styles.sectionTitle)}>Why Kotlin</div> |
| 48 | + |
| 49 | + <div className={styles.codeExamples}> |
| 50 | + <div className={styles.navigationBar}> |
| 51 | + <div className={styles.mobileMenuButton}> |
| 52 | + <Button mode={'clear'} size={'m'}> |
| 53 | + Mobile button |
| 54 | + </Button> |
| 55 | + </div> |
| 56 | + |
| 57 | + <TabList |
| 58 | + value={activeIndex} |
| 59 | + onChange={(v) => setActiveIndex(v)} |
| 60 | + mode={'rock'} |
| 61 | + size={'m'} |
| 62 | + className={styles.tabList} |
| 63 | + > |
| 64 | + <Tab>Simple</Tab> |
| 65 | + <Tab>Asynchronous</Tab> |
| 66 | + <Tab>Object-oriented</Tab> |
| 67 | + <Tab>Functional</Tab> |
| 68 | + <Tab>Ideal for tests</Tab> |
| 69 | + </TabList> |
| 70 | + |
| 71 | + <div> |
| 72 | + <Button |
| 73 | + mode={'clear'} |
| 74 | + size={'m'} |
| 75 | + icon={<CodeIcon />} |
| 76 | + className={styles.openInPlaygoundButton} |
| 77 | + > |
| 78 | + Open in Playground |
| 79 | + </Button> |
| 80 | + <Button mode={'clear'} size={'m'} icon={<PlayIcon />} onClick={handleRunButton}> |
| 81 | + Run |
| 82 | + </Button> |
| 83 | + </div> |
| 84 | + </div> |
| 85 | + |
| 86 | + <div className="tab-content kotlin-code-examples-section"> |
| 87 | + <ContentSwitcher index={activeIndex}> |
| 88 | + <div className={styles.tab} key={0}> |
| 89 | + <CodeBlock>{simpleExample}</CodeBlock> |
| 90 | + </div> |
| 91 | + <div className={styles.tab} key={1}> |
| 92 | + <CodeBlock>{asyncExample}</CodeBlock> |
| 93 | + </div> |
| 94 | + <div className={styles.tab} key={2}> |
| 95 | + <CodeBlock>{oopExample}</CodeBlock> |
| 96 | + </div> |
| 97 | + <div className={styles.tab} key={3}> |
| 98 | + <CodeBlock>{functionalExample}</CodeBlock> |
| 99 | + </div> |
| 100 | + <div className={styles.tab} key={4}> |
| 101 | + <CodeBlock>{testsExample}</CodeBlock> |
| 102 | + </div> |
| 103 | + </ContentSwitcher> |
| 104 | + </div> |
| 105 | + </div> |
| 106 | + |
| 107 | + <Button mode={'outline'} size={'l'} className={styles.getStartedButton}> |
| 108 | + Get started |
| 109 | + </Button> |
| 110 | + </div> |
| 111 | + </section> |
| 112 | + </ThemeProvider> |
| 113 | + ); |
| 114 | +}; |
0 commit comments