Skip to content

Commit

Permalink
Added button render position config
Browse files Browse the repository at this point in the history
  • Loading branch information
guywillis committed Jan 17, 2025
1 parent 1e650ad commit 4ed3006
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 20 deletions.
1 change: 1 addition & 0 deletions example.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"_scrollPrompt": {
"_isEnabled": true,
"instruction": "{{_globals._extensions._scrollPrompt.scrollDown}}",
"_buttonPosition": "left",
"_iconClass": "icon-controls-down"
}
36 changes: 34 additions & 2 deletions less/scrollPrompt.less
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
.scrollPrompt {
margin-top: 1.5rem;
margin-top: 1rem;

&__inner {
display: flex;
}

&__inner.align-button-top,
&__inner.align-button-bottom {
flex-direction: column;
align-items: flex-start;
}

&__inner.align-button-left,
&__inner.align-button-right {
flex-direction: row;
align-items: center;
}

&__inner.align-button-top &__instruction {
margin-top: @component-instruction-margin;
}

&__inner.align-button-bottom &__instruction {
margin-bottom: @component-instruction-margin;
}

&__inner.align-button-left &__instruction {
margin-inline-start: @component-instruction-margin;
}

&__inner.align-button-right &__instruction {
margin-inline-end: @component-instruction-margin;
}
}

// --------------------------------------------------
// THEME
// --------------------------------------------------
.scrollPrompt {
&__instruction {
margin-inline-start: 1rem;
.instruction-text;
}
}
52 changes: 52 additions & 0 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@
"validators": [],
"translatable": true
},
"_buttonPosition": {
"type": "string",
"required": true,
"enum": ["left", "top", "right", "bottom"],
"default": "left",
"title": "Button position",
"inputType": {
"type": "Select",
"options": ["left", "right", "top", "bottom"]
},
"validators": ["required"],
"help": "Set the button rendering position in relation to the instruction text."
},
"_iconClass": {
"type": "string",
"required": false,
Expand Down Expand Up @@ -70,6 +83,19 @@
"validators": [],
"translatable": true
},
"_buttonPosition": {
"type": "string",
"required": true,
"enum": ["left", "top", "right", "bottom"],
"default": "left",
"title": "Button position",
"inputType": {
"type": "Select",
"options": ["left", "right", "top", "bottom"]
},
"validators": ["required"],
"help": "Set the button rendering position in relation to the instruction text."
},
"_iconClass": {
"type": "string",
"required": false,
Expand Down Expand Up @@ -104,6 +130,19 @@
"validators": [],
"translatable": true
},
"_buttonPosition": {
"type": "string",
"required": true,
"enum": ["left", "top", "right", "bottom"],
"default": "left",
"title": "Button position",
"inputType": {
"type": "Select",
"options": ["left", "right", "top", "bottom"]
},
"validators": ["required"],
"help": "Set the button rendering position in relation to the instruction text."
},
"_iconClass": {
"type": "string",
"required": false,
Expand Down Expand Up @@ -138,6 +177,19 @@
"validators": [],
"translatable": true
},
"_buttonPosition": {
"type": "string",
"required": true,
"enum": ["left", "top", "right", "bottom"],
"default": "left",
"title": "Button position",
"inputType": {
"type": "Select",
"options": ["left", "right", "top", "bottom"]
},
"validators": ["required"],
"help": "Set the button rendering position in relation to the instruction text."
},
"_iconClass": {
"type": "string",
"required": false,
Expand Down
13 changes: 13 additions & 0 deletions schema/block.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@
"title": "Instruction text",
"default": "{{_globals._extensions._scrollPrompt.scrollDown}}"
},
"_buttonPosition": {
"type": "string",
"title": "Button position",
"description": "Set the button rendering position in relation to the instruction text.",
"default": "left",
"enum": [
"left",
"right",
"top",
"bottom"
],
"_backboneForms": "Select"
},
"_iconClass": {
"type": "string",
"title": "Button icon class",
Expand Down
13 changes: 13 additions & 0 deletions schema/component.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@
"title": "Instruction text",
"default": "{{_globals._extensions._scrollPrompt.scrollDown}}"
},
"_buttonPosition": {
"type": "string",
"title": "Button position",
"description": "Set the button rendering position in relation to the instruction text.",
"default": "left",
"enum": [
"left",
"right",
"top",
"bottom"
],
"_backboneForms": "Select"
},
"_iconClass": {
"type": "string",
"title": "Button icon class",
Expand Down
13 changes: 13 additions & 0 deletions schema/contentobject.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@
"title": "Instruction text",
"default": "{{_globals._extensions._scrollPrompt.scrollDown}}"
},
"_buttonPosition": {
"type": "string",
"title": "Button position",
"description": "Set the button rendering position in relation to the instruction text.",
"default": "left",
"enum": [
"left",
"right",
"top",
"bottom"
],
"_backboneForms": "Select"
},
"_iconClass": {
"type": "string",
"title": "Button icon class",
Expand Down
13 changes: 13 additions & 0 deletions schema/course.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@
"title": "Instruction text",
"default": "{{_globals._extensions._scrollPrompt.scrollDown}}"
},
"_buttonPosition": {
"type": "string",
"title": "Button position",
"description": "Set the button rendering position in relation to the instruction text.",
"default": "left",
"enum": [
"left",
"right",
"top",
"bottom"
],
"_backboneForms": "Select"
},
"_iconClass": {
"type": "string",
"title": "Button icon class",
Expand Down
39 changes: 21 additions & 18 deletions templates/scrollPrompt.jsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import React from 'react';
import { classes, compile } from 'core/js/reactHelpers';
import { classes, compile, templates } from 'core/js/reactHelpers';

export default function ScrollPrompt (props) {
const {
_scrollPrompt,
onScrollPromptClick
_scrollPrompt
} = props;

const buttonPosition = _scrollPrompt._buttonPosition;
let buttonRenderOrder = 'first';

if (buttonPosition === 'bottom' || buttonPosition === 'right') {
buttonRenderOrder = 'last';
}

return (
<div
className='scrollPrompt__inner a11y-ignore'
className={classes([
'scrollPrompt__inner',
buttonPosition && `align-button-${buttonPosition}`,
'a11y-ignore'
])}
aria-hidden='true'
>

<button
className='btn-icon scrollPrompt__btn'
onClick={onScrollPromptClick}
>
<span
className={classes([
'icon',
_scrollPrompt._iconClass
? _scrollPrompt._iconClass
: 'icon-controls-down'
])}
aria-hidden='true'
/>
</button>
{buttonRenderOrder === 'first' &&
<templates.scrollPromptButton {...props} />
}

{_scrollPrompt.instruction &&
<div
Expand All @@ -35,6 +34,10 @@ export default function ScrollPrompt (props) {
/>
}

{buttonRenderOrder === 'last' &&
<templates.scrollPromptButton {...props} />
}

</div>
);
}
29 changes: 29 additions & 0 deletions templates/scrollPromptButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { classes } from 'core/js/reactHelpers';

export default function ScrollPromptButton (props) {

const {
_scrollPrompt,
onScrollPromptClick
} = props;

return (

<button
className='btn-icon scrollPrompt__btn'
onClick={onScrollPromptClick}
>
<span
className={classes([
'icon',
_scrollPrompt._iconClass
? _scrollPrompt._iconClass
: 'icon-controls-down'
])}
aria-hidden='true'
/>
</button>

);
}

0 comments on commit 4ed3006

Please sign in to comment.