Skip to content
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

✨ feat(accordions-group): ajoute un attribut pour dégrouper [DS-3687] #860

Merged
merged 6 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/component/accordion/example/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
<%- sample('Accordéon', './sample/accordion', {}, true); %>

<%- sample('Groupe d‘accordéons', './sample/accordions-group', {}, true); %>

<%- sample('Groupe d‘accordéons dissociés', './sample/accordions-group', {accordionsGroup: {group: false}}, true); %>
8 changes: 5 additions & 3 deletions src/component/accordion/example/sample/accordions-group.ejs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<%
const accordions = [];
let accordionsGroup = locals.accordionsGroup || {};

const accordions = [];
for (let i = 0; i < 6; i++) accordions.push({
label: 'Intitulé accordéon',
content: randomContent(),
id: uniqueId('accordion'),
});

const accordionsGroup = {
accordions: accordions
accordionsGroup = {
accordions: accordions,
...accordionsGroup
}
%>

Expand Down
9 changes: 7 additions & 2 deletions src/component/accordion/template/ejs/accordions-group.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
%>
<% eval(include('../../../../core/index.ejs')); %>

<% let accordionsGroup = locals.accordionsGroup || {accordions: []} %>
<div class="<%= prefix %>-accordions-group" >
<%
let accordionsGroup = locals.accordionsGroup || {accordions: []}
let attributes = accordionsGroup.attributes || {};
if (accordionsGroup.group !== undefined) attributes[`data-${prefix}-group`] = accordionsGroup.group;
%>

<div <%- includeAttrs(attributes); %> class="<%= prefix %>-accordions-group">
<%
for (let i = 0; i < accordionsGroup.accordions.length; i++) {
%>
Expand Down
9 changes: 9 additions & 0 deletions src/component/navigation/script/navigation/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Navigation extends api.core.CollapsesGroup {
this.listen('focusout', this.focusOutHandler.bind(this));
this.listen('mousedown', this.mouseDownHandler.bind(this));
this.listenClick({ capture: true });
this.isResizing = true;
}

validate (member) {
Expand Down Expand Up @@ -73,6 +74,14 @@ class Navigation extends api.core.CollapsesGroup {
if (value === -1 && this.current && this.current.hasFocus) this.current.focus();
super.index = value;
}

get canUngroup () {
return !this.isBreakpoint(api.core.Breakpoints.LG);
}

resize () {
this.update();
}
}

export { Navigation };
4 changes: 4 additions & 0 deletions src/core/script/collapse/collapses-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class CollapsesGroup extends DisclosuresGroup {
static get instanceClassName () {
return 'CollapsesGroup';
}

get canUngroup () {
return true;
}
}

export { CollapsesGroup };
3 changes: 2 additions & 1 deletion src/core/script/disclosure/disclosure-selector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ns from '../api/utilities/namespace.js';

export const DisclosureSelector = {
PREVENT_CONCEAL: ns.attr.selector('prevent-conceal')
PREVENT_CONCEAL: ns.attr.selector('prevent-conceal'),
GROUP: ns.attr('group')
};
33 changes: 32 additions & 1 deletion src/core/script/disclosure/disclosures-group.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Instance } from '../api/modules/register/instance.js';
import { DisclosureEmission } from './disclosure-emission.js';
import { completeAssign } from '../api/utilities/property/complete-assign.js';
import { DisclosureSelector } from './disclosure-selector.js';

class DisclosuresGroup extends Instance {
constructor (disclosureInstanceClassName, jsAttribute) {
Expand All @@ -10,6 +11,7 @@ class DisclosuresGroup extends Instance {
this._index = -1;
this._isRetrieving = false;
this._hasRetrieved = false;
this._isGrouped = true;
}

static get instanceClassName () {
Expand All @@ -21,6 +23,7 @@ class DisclosuresGroup extends Instance {
this.addAscent(DisclosureEmission.RETRIEVE, this.retrieve.bind(this));
this.addAscent(DisclosureEmission.REMOVED, this.update.bind(this));
this.descend(DisclosureEmission.GROUP);
this._isGrouped = this.getAttribute(DisclosureSelector.GROUP) !== 'false';
this.update();
}

Expand All @@ -46,6 +49,12 @@ class DisclosuresGroup extends Instance {
},
get hasFocus () {
return scope.hasFocus;
},
set isGrouped (value) {
scope.isGrouped = value;
},
get isGrouped () {
return scope.isGrouped;
}
};

Expand Down Expand Up @@ -134,7 +143,7 @@ class DisclosuresGroup extends Instance {
if (value === i) {
if (!member.isDisclosed) member.disclose(true);
} else {
if (member.isDisclosed) member.conceal(true);
if ((this.isGrouped || !this.canUngroup) && member.isDisclosed) member.conceal(true);
}
}
this.apply();
Expand All @@ -155,6 +164,28 @@ class DisclosuresGroup extends Instance {
return false;
}

set isGrouped (value) {
const isGrouped = !!value;
if (this._isGrouped === isGrouped) return;
this._isGrouped = isGrouped;
this.setAttribute(DisclosureSelector.GROUP, !!value);
this.update();
}

get isGrouped () {
return this._isGrouped;
}

get canUngroup () {
return false;
}

mutate (attributesNames) {
if (attributesNames.includes(DisclosureSelector.GROUP)) {
this.isGrouped = this.getAttribute(DisclosureSelector.GROUP) !== 'false';
}
}

apply () {}

dispose () {
Expand Down