Skip to content

Commit dce1c7f

Browse files
authored
Merge pull request #579 from gselderslaghs/cards-buttons-mixin
enhancement(Cards) buttons mixin implementation + auto init
2 parents 3321da9 + 3c930db commit dce1c7f

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

sass/components/_cards.scss

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,13 @@
171171
border-radius: 0 0 2px 2px;
172172
}
173173

174-
border-top: 1px solid var(--md-sys-color-outline-variant);
175-
position: relative;
176-
background-color: inherit;
174+
// position: relative;
175+
padding: 0 1.6rem;
176+
// border-top: 1px solid var(--md-sys-color-outline-variant);
177+
// background-color: inherit;
177178

178-
a {
179+
// Replaced card links with buttons (Accessibility, @see https://github.com/materializecss/materialize/issues/565)
180+
/*a {
179181
padding: 16px 24px;
180182
display: inline-block;
181183
}
@@ -187,6 +189,33 @@
187189
&:hover {
188190
background-color: rgba(var(--md-sys-color-primary-numeric), 0.06);
189191
}
192+
}*/
193+
194+
a {
195+
@include btn(
196+
var(--btn-height),
197+
var(--btn-border-radius),
198+
var(--btn-padding),
199+
var(--btn-padding),
200+
var(--btn-font-size)
201+
);
202+
203+
&:first-child {
204+
margin-left: -1.6rem;
205+
}
206+
207+
&:last-child {
208+
margin-right: -1.6rem;
209+
}
210+
}
211+
212+
.btn {
213+
&.filled,
214+
&.tonal,
215+
&.elevated,
216+
&.outlined {
217+
margin: 0 .26rem 1.6rem 0;
218+
}
190219
}
191220
}
192221

src/cards.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,15 @@ export class Cards extends Component<CardsOptions> implements Openable {
173173
}
174174
this._removeRevealCloseEventHandlers();
175175
};
176+
177+
static Init() {
178+
if (typeof document !== 'undefined')
179+
// Handle initialization of static cards.
180+
document.addEventListener('DOMContentLoaded', () => {
181+
const cards = document.querySelectorAll('.card');
182+
cards.forEach((el) => {
183+
if (el && (el['M_Card'] == undefined)) this.init((el as HTMLElement));
184+
});
185+
});
186+
}
176187
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,4 @@ Forms.Init();
138138
Chips.Init();
139139
Waves.Init();
140140
Range.Init();
141+
Cards.Init();

0 commit comments

Comments
 (0)