-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(examples): update example js code for docsite #154
- Loading branch information
1 parent
ce33d61
commit c0b7ba5
Showing
22 changed files
with
280 additions
and
151 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 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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
export function setErrorOnValueChange(elem) { | ||
elem.addEventListener('auroSelect-valueSet', () => { | ||
if (+elem.value > 2) { | ||
elem.setAttribute('error', 'Quantity Exceeded'); | ||
} else if (elem.hasAttribute('error')) { | ||
elem.removeAttribute('error'); | ||
export function customErrorValidityExample(elem) { | ||
const customErrorValidityExample = document.querySelector('#primaryError'); | ||
|
||
customErrorValidityExample.addEventListener('auroSelect-valueSet', () => { | ||
if (+customErrorValidityExample.value > 2) { | ||
customErrorValidityExample.setAttribute('error', 'Quantity Exceeded'); | ||
} else if (customErrorValidityExample.hasAttribute('error')) { | ||
customErrorValidityExample.removeAttribute('error'); | ||
} | ||
}) | ||
}; |
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,9 +1,11 @@ | ||
export function setError(elem) { | ||
export function setErrorExample() { | ||
const setErrorExample = document.querySelector('#errorExample'); | ||
|
||
document.querySelector('#undefinedValueExampleBtnAddError').addEventListener('click', () => { | ||
elem.setAttribute('error', 'custom error'); | ||
setErrorExample.setAttribute('error', 'custom error'); | ||
}) | ||
|
||
document.querySelector('#undefinedValueExampleBtnRemoveError').addEventListener('click', () => { | ||
elem.removeAttribute('error'); | ||
setErrorExample.removeAttribute('error'); | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
export function setValue(elem) { | ||
export function valueExample() { | ||
const valueExample = document.querySelector('#valueExample'); | ||
|
||
document.querySelector('#validValueExampleBtn').addEventListener('click', () => { | ||
elem.value = 'arrival'; | ||
valueExample.value = 'arrival'; | ||
}) | ||
|
||
document.querySelector('#invalidValueExampleBtn').addEventListener('click', () => { | ||
elem.value = 'flight course'; | ||
valueExample.value = 'flight course'; | ||
}) | ||
|
||
document.querySelector('#undefinedValueExampleBtn').addEventListener('click', () => { | ||
elem.value = undefined; | ||
valueExample.value = undefined; | ||
}) | ||
} |
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,11 @@ | ||
export function valueExtractionExample() { | ||
const valueExtractionExample = document.querySelector('#valueExtraction'); | ||
const valueExtractionBtn = document.querySelector('#valueExtractionBtn'); | ||
|
||
valueExtractionBtn.addEventListener('click', () => { | ||
console.warn('Value selected:', valueExtractionExample.value); | ||
console.warn('Option selected:', valueExtractionExample.optionSelected); | ||
|
||
alert(`Value selected: ${valueExtractionExample.value}`); | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,86 +1,24 @@ | ||
function initializeExample(element, callback, retryCount) { | ||
const elem = document.querySelector(element); | ||
|
||
if (!elem || !elem.ready) { | ||
// If the component is not ready, retry until it is | ||
if (!retryCount && retryCount != 0) { | ||
retryCount = 0; | ||
} else { | ||
retryCount += 1; | ||
} | ||
import { customErrorValidityExample } from "../apiExamples/customErrorValidity"; | ||
import { setErrorExample } from "../apiExamples/errorApi"; | ||
import { nestedSelectExample } from "../apiExamples/nestedSelect"; | ||
import { valueExample } from "../apiExamples/value"; | ||
import { valueExtractionExample } from "../apiExamples/valueExtraction"; | ||
|
||
if (retryCount < 10) { | ||
setTimeout(initializeExample, 500, element, callback, retryCount); | ||
} else { | ||
console.error('Unable to initialize functional example code for:', element); | ||
} | ||
} else { | ||
callback(elem); | ||
export function initSelectApiExamples(initCount) { | ||
initCount = initCount || 0; | ||
|
||
try { | ||
customErrorValidityExample(); | ||
setErrorExample(); | ||
nestedSelectExample(); | ||
valueExample(); | ||
valueExtractionExample(); | ||
} catch { | ||
if (initCount <= 20) { | ||
// setTimeout handles issue where content is sometimes loaded after the functions get called | ||
setTimeout(() => { | ||
initSelectApiExamples(initCount + 1); | ||
}, 100); | ||
} | ||
} | ||
|
||
/** | ||
* Send alert to user when an option is selected | ||
*/ | ||
import { valueAlert } from './alertValue'; | ||
|
||
(function(){ | ||
initializeExample('auro-select#valueAlert', function(elem) { | ||
valueAlert(elem); | ||
}); | ||
}()); | ||
|
||
/** | ||
* Extract the value from auro-select element | ||
*/ | ||
import { getValue } from './extractValue'; | ||
|
||
(function(){ | ||
initializeExample('#valueExtraction', function(elem) { | ||
getValue(elem); | ||
}); | ||
}()); | ||
|
||
/** | ||
* Programmatically set value of auro-select | ||
*/ | ||
import { setValue } from './../apiExamples/value'; | ||
|
||
(function(){ | ||
initializeExample('#valueExample', function(elem) { | ||
setValue(elem); | ||
}); | ||
}()); | ||
|
||
/** | ||
* Show auro-select overflow when nested inside another element | ||
*/ | ||
import { openDialog } from './../apiExamples/nestedSelect'; | ||
|
||
(function(){ | ||
initializeExample('#nestedSelect', function() { | ||
openDialog(); | ||
}); | ||
}()); | ||
|
||
/** | ||
* Programmatically set error attribute | ||
*/ | ||
import { setError } from '../apiExamples/errorApi'; | ||
|
||
(function(){ | ||
initializeExample('#errorExample', function(elem) { | ||
setError(elem); | ||
}); | ||
}()); | ||
|
||
/** | ||
* Programmatically set error attribute based on specific condition | ||
*/ | ||
import { setErrorOnValueChange } from './../apiExamples/customErrorValidity'; | ||
|
||
(function(){ | ||
initializeExample('#primaryError', function(elem) { | ||
setErrorOnValueChange(elem); | ||
}); | ||
}()); | ||
} |
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
Oops, something went wrong.