woylie / flop_phoenix

Components for pagination, sortable tables and filter forms using Phoenix, Ecto and Flop
MIT License
385 stars 43 forks source link

Add support for :col_class on cols #327

Closed maltoe closed 6 months ago

maltoe commented 6 months ago

Hi @woylie,

I'm currently adding a relatively strict CSP header to one of our apps (i.e. no unsafe-inline) and the inline style attributes on the colgroup elements are violating the policy. With this patch, I'd be able to set the styles via classes instead.


This patch adds support for a new :col_class prop on :col and :action slots for table/1 which sets the class attribute on the generated colgroup. Additionally it removes empty style="" attributes.

Both of these changes are intended to prevent inline style attributes violating strict content-security-policies.

<:col col_style="width: 20rem;"></:col>
<:col col_class="some-class"></:col>
<:col></:col>

... renders the following colgroup:

<colgroup>
  <col style="width: 20rem"></col>
  <col class="some-class"></col>
  <col></col>
</colgroup>
coveralls commented 6 months ago

Coverage Status

coverage: 99.804% (+0.001%) from 99.803% when pulling 36fcb44c0c44530ddd4da2637f357063b488aa7d on maltoe:col-class into 41065630e5e69e64449b576cae73bb24ee165b8b on woylie:main.

woylie commented 6 months ago

Thank you! Do you think it would be better to add a col_attrs attribute instead, and eventually deprecate col_style?

woylie commented 6 months ago

Prior request: https://github.com/woylie/flop_phoenix/issues/223

maltoe commented 6 months ago

Thank you! Do you think it would be better to add a col_attrs attribute instead, and eventually deprecate col_style?

Seems reasonable, yes. Or how about just calling it colgroup to make it clear where these attrs go? colgroup: [style: "width: 10rem"]