-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSD8-1507 Replace chosen module with custom combo box (#1388)
- Loading branch information
Showing
29 changed files
with
13,152 additions
and
26 deletions.
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
This file was deleted.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
20 |
10 changes: 10 additions & 0 deletions
10
docroot/profiles/humsci/su_humsci_profile/js/select-lists/.gitignore
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.env.local | ||
|
||
# Yarn files. See https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored. | ||
.yarn/* | ||
!.yarn/cache | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions |
1 change: 1 addition & 0 deletions
1
docroot/profiles/humsci/su_humsci_profile/js/select-lists/.nvmrc
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
20 |
893 changes: 893 additions & 0 deletions
893
docroot/profiles/humsci/su_humsci_profile/js/select-lists/.yarn/releases/yarn-4.0.2.cjs
Large diffs are not rendered by default.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
docroot/profiles/humsci/su_humsci_profile/js/select-lists/.yarnrc.yml
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-4.0.2.cjs |
24 changes: 24 additions & 0 deletions
24
docroot/profiles/humsci/su_humsci_profile/js/select-lists/dist/index.html
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><title>Widgets</title><meta name="viewport" content="width=device-width,initial-scale=1"/><link rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/><link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet"/><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" integrity="sha512-1ycn6IcaQQ40/MKBW2W4Rhis/DbILU74C1vSrLJxCq57o941Ym01SwNsOMqvEBFlcgUa6xLiPY/NS5R+E6ztJQ==" crossorigin="anonymous" referrerpolicy="no-referrer"/><style>body { | ||
font-family: 'Inter', sans-serif; | ||
} | ||
|
||
.preview { | ||
width: 100%; | ||
max-width: 1100px; | ||
margin: 80px auto; | ||
border: 1px dashed rgba(0, 0, 0, 0.2); | ||
position: relative; | ||
padding: 1rem; | ||
} | ||
|
||
.preview::before { | ||
content: 'WIDGET PREVIEW'; | ||
position: absolute; | ||
display: block; | ||
top: -18px; | ||
font-size: 11px; | ||
color: rgba(0, 0, 0, 0.5); | ||
} | ||
.visually-hidden { | ||
display: none; | ||
}</style><script defer="defer" src="/islands/select-list-filters.island.js"></script></head><body><div class="preview"><div id="gradgrow-filters-island"></div><form class="views-exposed-form bef-exposed-form" style="margin-top:20px; border: 4px solid red" data-drupal-selector="views-exposed-form-vpge-grad-grow-filters-block" action="/grad-grow-filters" id="views-exposed-form-vpge-grad-grow-filters-block" accept-charset="UTF-8" data-once="exposed-form"><div class="select-preact js-form-item form-item js-form-type-select form-item-competency js-form-item-competency"><label for="edit-competency">Filter by competency</label> <select data-drupal-selector="edit-competency" multiple="multiple" name="competency[]" id="edit-competency" size="9" class="form-select" data-once="chosen"><option value="1111">Communication</option><option value="1116" disabled="disabled">-Writing</option><option value="1181">-Speaking & presenting</option><option value="1236">-Interpersonal communication</option><option value="1186">Teaching and Mentoring</option><option value="1246">-Pedagogy & assessment</option><option value="1191">-Mentoring</option><option value="1051">-Course & training design</option><option value="1081">Professionalism</option><option value="1121">-Academic & research integrity</option><option value="1086">-Stress management & work/life balance</option><option value="1126">-Critical & analytical thinking</option><option value="1131">-Professional ethics</option><option value="1256">Diversity Equity & Inclusion</option><option value="1216">-Inclusive mindset</option><option value="1221">-Equitable & inclusive environments</option><option value="1301">-Teamwork & collaboration</option><option value="1271">Leadership & Management</option><option value="1071">-Negotiation & conflict resolution</option><option value="1076">-Innovation & problem-solving</option><option value="1096">-Management of people & projects</option><option value="1101">-Leadership & entrepreneurial skills</option><option value="1196">Career Development</option></select></div><div class="select-preact js-form-item form-item js-form-type-select form-item-content-type js-form-item-content-type"><label for="edit-content-type">Filter by learning opportunity</label> <select data-drupal-selector="edit-content-type" id="edit-content-type" name="content_type" class="form-select"><option value="All" selected="selected">- Any -</option><option value="1">Event</option><option value="2">Resource</option></select></div><div class="select-preact js-form-item form-item js-form-type-select form-item-commitment js-form-item-commitment"><label for="edit-commitment">Filter by time commitment</label> <select data-drupal-selector="edit-commitment" id="edit-commitment" name="commitment" class="form-select"><option value="All">All</option><option value="756">< 3 hours</option><option value="751">3 - 8 hours</option><option value="746" selected="selected">> 8 hours</option><option value="741">Self-guided</option></select></div><div data-drupal-selector="edit-actions" class="form-actions js-form-wrapper form-wrapper" id="edit-actions"><input data-drupal-selector="edit-submit-vpge-grad-grow" type="submit" id="edit-submit-vpge-grad-grow" value="Apply filter" class="button js-form-submit form-submit"></div></form></div></body></html> |
25 changes: 25 additions & 0 deletions
25
...files/humsci/su_humsci_profile/js/select-lists/dist/islands/select-list-filters.island.js
Large diffs are not rendered by default.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
docroot/profiles/humsci/su_humsci_profile/js/select-lists/package.json
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "preact-island-examples", | ||
"version": "0.1.0", | ||
"description": "", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"umd:main": "dist/index.umd.js", | ||
"module": "dist/index.module.js", | ||
"source": "src/index.tsx", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "webpack --env prod", | ||
"dev": "webpack serve --env dev" | ||
}, | ||
"dependencies": { | ||
"@heroicons/react": "^2.1.1", | ||
"@mui/base": "^5.0.0-beta.32", | ||
"preact": "^10.19.3", | ||
"styled-components": "^6.1.8" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.23.0", | ||
"@babel/preset-env": "^7.23.8", | ||
"@babel/preset-react": "^7.23.3", | ||
"@babel/preset-typescript": "^7.23.3", | ||
"@types/webpack": "^5.28.5", | ||
"babel-loader": "^9.1.3", | ||
"css-loader": "^6.9.1", | ||
"dotenv-webpack": "^8.0.1", | ||
"html-webpack-plugin": "^5.6.0", | ||
"preact-island": "^1.1.2", | ||
"terser-webpack-plugin": "^5.3.10", | ||
"webpack": "^5.89.0", | ||
"webpack-cli": "^5.1.4", | ||
"webpack-dev-server": "^4.15.1" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
108 changes: 108 additions & 0 deletions
108
docroot/profiles/humsci/su_humsci_profile/js/select-lists/src/select-list-filters.island.tsx
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import {createIslandWebComponent} from 'preact-island' | ||
import SelectList from "./select-list"; | ||
import {useEffect, useRef, useState} from "preact/compat"; | ||
|
||
const FilterIsland = ({focus = false}) => { | ||
const ref = useRef(); | ||
const [originalSelect, setOriginalSelect] = useState(null); | ||
const [label, setLabel] = useState(''); | ||
|
||
useEffect(() => { | ||
setOriginalSelect(ref.current.parentNode.querySelector('select')); | ||
setLabel(ref.current.parentNode.querySelector('label').textContent); | ||
|
||
// Use visibility because when display none, the field isn't updated | ||
// sometimes after ajax. | ||
const origSelect = ref.current.parentNode.querySelector('select'); | ||
origSelect.setAttribute('aria-hidden', 'true'); | ||
origSelect.style.visibility = 'hidden' | ||
origSelect.style.height = '0' | ||
origSelect.style.position = 'absolute' | ||
|
||
const origLabel = ref.current.parentNode.querySelector('label'); | ||
origLabel.style.visibility = 'hidden' | ||
origLabel.style.height = '0' | ||
origLabel.style.position = 'absolute' | ||
}, []) | ||
|
||
const getSelectOptions = (selectElement) => { | ||
const options = []; | ||
|
||
const optionElements = selectElement.children; | ||
|
||
for (let i = 0; i < optionElements.length; i++) { | ||
const option = optionElements[i]; | ||
const value = option.getAttribute('value') | ||
const label = option.textContent; | ||
options.push({value, label, disabled: option.getAttribute('disabled') === 'disabled'}); | ||
} | ||
return options; | ||
} | ||
|
||
const onSelectChange = (e, value) => { | ||
if (!originalSelect.getAttribute('multiple')) return originalSelect.value = value; | ||
|
||
for (let option of originalSelect.children) { | ||
if (value.includes(option.getAttribute('value'))) { | ||
option.setAttribute('selected', 'selected') | ||
} else { | ||
option.removeAttribute('selected'); | ||
} | ||
} | ||
} | ||
|
||
const getDefaultValue = () => { | ||
let defaultValue = []; | ||
for (let option of originalSelect?.children) { | ||
if (option.getAttribute('selected')) { | ||
if (!originalSelect.getAttribute('multiple')) return option.getAttribute('value'); | ||
|
||
defaultValue.push(option.getAttribute('value')) | ||
} | ||
} | ||
return defaultValue; | ||
} | ||
|
||
const selectOptions = originalSelect && getSelectOptions(originalSelect); | ||
|
||
return ( | ||
<div ref={ref}> | ||
{originalSelect && | ||
<SelectList | ||
name={originalSelect.getAttribute('id') + '-preact'} | ||
options={selectOptions.filter(item => item.value !== 'All')} | ||
label={label} | ||
multiple={originalSelect.getAttribute('multiple') === 'multiple'} | ||
onChange={onSelectChange} | ||
defaultValue={getDefaultValue()} | ||
emptyLabel={selectOptions.find(item => item.value === 'All')?.label} | ||
/> | ||
} | ||
</div> | ||
) | ||
} | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
const island = createIslandWebComponent('combobox-select-list', FilterIsland) | ||
island.render({ | ||
selector: `.select-preact`, | ||
}) | ||
} else { | ||
(function () { | ||
Drupal.behaviors.selectPreact = { | ||
attach: function (context) { | ||
let contextClass = '' | ||
try { | ||
contextClass = '.' + context.getAttribute('class').replace(/ /g, '.'); | ||
} catch (e) { | ||
} | ||
|
||
const island = createIslandWebComponent('combobox-select-list', FilterIsland) | ||
island.render({ | ||
selector: `${contextClass} .select-preact`, | ||
initialProps: {focus: contextClass.indexOf('js-view-dom-id') >= 0} | ||
}) | ||
} | ||
}; | ||
})(); | ||
} |
Oops, something went wrong.