diff --git a/assets/sass/_demo.scss b/assets/sass/_demo.scss index 050d421..acb9f5e 100644 --- a/assets/sass/_demo.scss +++ b/assets/sass/_demo.scss @@ -43,3 +43,17 @@ .demo__time-split--formatting { background: darken($color-accent, 20%); } + +.demo__languages { + display: flex; + padding: 0; + flex-wrap: wrap; + margin-bottom: -.5rem; + margin-right: -.5rem; + + li { + list-style: none; + margin-right: .5rem; + margin-bottom: .5rem; + } +} diff --git a/assets/ts/app.ts b/assets/ts/app.ts index 7028ea7..279bd53 100644 --- a/assets/ts/app.ts +++ b/assets/ts/app.ts @@ -4,7 +4,7 @@ import 'bootstrap' import '@fortawesome/fontawesome-pro/css/all.min.css' import 'typeface-raleway' import '../sass/style.scss' -import './try-form' +import './demo' $('[data-toggle="tooltip"]').tooltip(); diff --git a/assets/ts/try-form.tsx b/assets/ts/demo.tsx similarity index 83% rename from assets/ts/try-form.tsx rename to assets/ts/demo.tsx index 9308fd9..da54692 100644 --- a/assets/ts/try-form.tsx +++ b/assets/ts/demo.tsx @@ -1,9 +1,38 @@ import * as React from "react"; import { useState } from "react"; import * as ReactDOM from "react-dom" +import { useFetch } from "react-async"; const formatter = new Intl.NumberFormat(undefined, { maximumFractionDigits: 2 }); +type Language = { + name: string; + class: string; + embeddable: boolean; + standalone: boolean; +} + +type LanguageSelectorProps = { + language: string; + onSelect(language: Language): void; +} + +const LanguageSelector = ({ language, onSelect }: LanguageSelectorProps) => { + const { data: languages, isPending } = useFetch("/languages", { headers: { "Accept": "application/json" }}); + + const regex = language && new RegExp(`${language}`); + const matching = languages && languages.filter(current => !language || current.name.match(regex)); + const isValidLanguage = languages && typeof languages.find(current => current.name === language) !== "undefined"; + + return isPending ? null : +}; + type HighlightFormProps = { onSubmit(code: string, language: string); } @@ -19,6 +48,8 @@ const HighlightForm = ({ onSubmit }: HighlightFormProps) => { const handleSubmit = () => onSubmit && onSubmit(code, language); + const handleLanguageSelection = language => setLanguage(language.name); + return (
@@ -42,8 +73,7 @@ const HighlightForm = ({ onSubmit }: HighlightFormProps) => {
-
-
+