-
-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add BCP47 language picker in frontmatter #2720
Draft
fonsp
wants to merge
2
commits into
main
Choose a base branch
from
bcp47-picker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+66
−6
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { has_ctrl_or_cmd_pressed } from "../common/KeyboardShortcuts.js" | |
import _ from "../imports/lodash.js" | ||
|
||
import "https://cdn.jsdelivr.net/gh/fonsp/[email protected]/lib/rebel-tag-input.mjs" | ||
import "https://esm.sh/[email protected]?pin=v134&target=es2020" | ||
|
||
//@ts-ignore | ||
import immer from "../imports/immer.js" | ||
|
@@ -179,7 +180,7 @@ const clean_data = (obj) => { | |
return _.isEmpty(a) ? null : a | ||
} | ||
|
||
const special_field_names = ["tags", "date", "license", "url", "color"] | ||
const special_field_names = ["tags", "date", "language", "license", "url", "color"] | ||
|
||
const field_type = (name) => { | ||
for (const t of special_field_names) { | ||
|
@@ -195,8 +196,12 @@ const Input = ({ value, on_value, type, id }) => { | |
|
||
useLayoutEffect(() => { | ||
if (!input_ref.current) return | ||
input_ref.current.value = value | ||
}, [input_ref.current, value]) | ||
if (type === "language") { | ||
input_ref.current.setAttribute("value", value) | ||
} else { | ||
input_ref.current.value = value | ||
} | ||
}, [input_ref.current, value, type]) | ||
|
||
useLayoutEffect(() => { | ||
if (!input_ref.current) return | ||
|
@@ -205,18 +210,21 @@ const Input = ({ value, on_value, type, id }) => { | |
on_value(input_ref.current.value) | ||
} | ||
|
||
input_ref.current.addEventListener("input", listener) | ||
let event_name = type === "language" ? "change" : "input" | ||
input_ref.current.addEventListener(event_name, listener) | ||
return () => { | ||
input_ref.current?.removeEventListener("input", listener) | ||
input_ref.current?.removeEventListener(event_name, listener) | ||
} | ||
}, [input_ref.current]) | ||
}, [input_ref.current, type]) | ||
|
||
const placeholder = type === "url" ? "https://..." : undefined | ||
|
||
return type === "tags" | ||
? html`<rbl-tag-input id=${id} ref=${input_ref} />` | ||
: type === "license" | ||
? LicenseInput({ ref: input_ref, id }) | ||
: type === "language" | ||
? LanguageInput({ ref: input_ref, id }) | ||
: html`<input type=${type} id=${id} ref=${input_ref} placeholder=${placeholder} />` | ||
} | ||
|
||
|
@@ -236,3 +244,7 @@ const LicenseInput = ({ ref, id }) => { | |
<datalist id="oss-licenses">${licenses.map((name) => html`<option>${name}</option>`)}</datalist> | ||
` | ||
} | ||
|
||
const LanguageInput = ({ ref, id }) => { | ||
return html`<bcp47-picker ref=${ref} id=${id}></bcp47-picker>` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
@import url("https://cdn.jsdelivr.net/npm/[email protected]/dist/dialog-polyfill.css"); | ||
@import url("https://cdn.jsdelivr.net/npm/[email protected]/dist/bcp47-picker.css"); | ||
@import url("https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"); | ||
|
||
/* @import url("https://fonts.googleapis.com/css?family=Roboto+Mono:400,400i,500,700&display=swap&subset=cyrillic,cyrillic-ext,greek,greek-ext,latin-ext"); */ | ||
@import url("https://cdn.jsdelivr.net/npm/@fontsource/[email protected]/400.css"); | ||
|
@@ -25,6 +27,52 @@ | |
|
||
@import url("./featured-card.css"); | ||
|
||
.bootstrap .input-group { | ||
position: relative; | ||
display: flex; | ||
flex-wrap: wrap; | ||
align-items: stretch; | ||
width: 100%; | ||
} | ||
|
||
.bootstrap .list-group { | ||
display: flex; | ||
flex-direction: column; | ||
padding-left: 0; | ||
margin-bottom: 0; | ||
border-radius: 0.25rem; | ||
} | ||
.bootstrap .list-group-item.active { | ||
z-index: 2; | ||
color: #fff; | ||
background-color: #0d6efd; | ||
border-color: #0d6efd; | ||
} | ||
|
||
.bootstrap .gap-2 { | ||
gap: 0.5rem !important; | ||
} | ||
.bootstrap .d-flex { | ||
display: flex !important; | ||
} | ||
.bootstrap .form-control { | ||
display: block; | ||
width: 100%; | ||
padding: 0.375rem 0.75rem; | ||
font-size: 1rem; | ||
font-weight: 400; | ||
line-height: 1.5; | ||
color: #212529; | ||
background-color: #fff; | ||
background-clip: padding-box; | ||
border: 1px solid #ced4da; | ||
-webkit-appearance: none; | ||
-moz-appearance: none; | ||
appearance: none; | ||
border-radius: 0.25rem; | ||
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; | ||
} | ||
|
||
/* VARIABLES */ | ||
|
||
:root { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one is pretty big 🤔 (165kb)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i also don't want it. i wish bcp47 had a bundle that included all the styles that it needs, scoped to the element but i think we need to do that by hand. You can see I started working on this in this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is one place where the PR got stuck