Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
spelkey-ucd committed Feb 12, 2024
1 parent 0d0d8d8 commit 284c3fd
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/editor/lib/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import career from "./ucd-theme-career";
import careers from "./ucd-theme-careers";
import categoryFilter from "./ucd-theme-category-filter";
import contactList from "./ucd-theme-contact-list";
import factoid from "./ucd-theme-factoid";
import faq from "./ucd-theme-faq";
import faqItem from "./ucd-theme-faq-item";
import featuredArticle from "./ucd-theme-featured-article";
Expand Down Expand Up @@ -65,6 +66,7 @@ export default [
careers,
categoryFilter,
contactList,
factoid,
faq,
faqItem,
featuredArticle,
Expand Down
141 changes: 141 additions & 0 deletions src/editor/lib/blocks/ucd-theme-factoid/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { html, UCDIcons } from "../../utils";
import { ToolbarColorPicker, ToolbarLinkPicker, IconPicker } from "../../block-components";
import { useBlockProps, BlockControls } from '@wordpress/block-editor';
import { useRef, useEffect, createRef } from "@wordpress/element";
import { ToolbarButton } from "@wordpress/components";

import classnames from 'classnames';


export default ( props ) => {
const { attributes, setAttributes } = props;
const blockProps = useBlockProps();
const iconPickerRef = createRef();


const onIconClick = () => {
if ( iconPickerRef.current ) {
iconPickerRef.current.openModal();
}
}

// set up icon picker
const onIconSelect = (icon) => {
setAttributes({icon: `${icon.iconSet}:${icon.icon}`})
}

// set up link picker
const onHrefChange = (value) => {
let attrs = {
href: value.url,
newTab: value.opensInNewTab ? true : false,
postId: 0,
taxId: 0
}
if ( value.kind == 'post-type' ){
attrs.postId = value.id;
}
else if ( value.kind == 'taxonomy' ) {
attrs.taxId = value.id
}
setAttributes(attrs);
}
const hrefContent = (() => {
let value = {opensInNewTab: attributes.newTab, url: ""};
if ( attributes.href ) {
value.url = attributes.href;
}
return value;
})();

// set up color picker
const onColorChange = (value) => {
setAttributes( {brandColor: value ? value.slug : "" } );
}

const classes = classnames({
'factoid': true,
[`category-brand--${attributes.brandColor}`]: attributes.brandColor,
'factoid--brackets': attributes.brackets
})

return html`
<div ...${ blockProps }>
<${BlockControls} group="block">
<${ToolbarLinkPicker} onChange=${onHrefChange} value=${hrefContent} />
<${ToolbarColorPicker}
onChange=${onColorChange}
value=${attributes.brandColor}
ucdBlock="priority-link"
/>
<${ToolbarButton}
icon=${UCDIcons.renderPublic("fa-right-to-bracket")}
onClick=${ () => {setAttributes({'brackets': !attributes.brackets})}}
isPressed=${attributes.brackets}
label="Toggle 'Brackets' Modifier"
/>
</${BlockControls}>
<${IconPicker}
ref=${iconPickerRef}
onChange=${onIconSelect}
selectedIcon=${attributes.icon}
></${IconPicker}>
<style>
.factoid input {
border: none;
box-shadow: none;
text-align: center;
color: var(--forced-contrast-heading-primary, #13639e);
}
.factoid input:focus {
background-color: transparent;
}
.factoid input::placeholder {
color: var(--forced-contrast-heading-primary, #13639e);
}
.factoid textarea {
border: none;
box-shadow: none;
text-align: center;
color: var(--forced-contrast, #022851);
}
.factoid textarea:focus {
background-color: transparent;
}
.factoid textarea::placeholder {
color: var(--forced-contrast, #022851);
}
</style>
<div className="${classes}">
<a className="factoid__link">
<div className="factoid__bracket-one"></div>
<div className="factoid__bracket-wrapper">
<div className="factoid__figure factoid__icon" onClick=${onIconClick}>
<ucdlib-icon icon=${attributes.icon}></ucdlib-icon>
</div>
<div className="factoid__body">
<h2 className="factoid__big-text">
<input
type="text"
value=${attributes.bigText}
placeholder="Big Text..."
onChange=${(e) => setAttributes({bigText: e.target.value})} />
</h2>
<h3 className="factoid__small-text">
<textarea
value=${attributes.smallText}
placeholder="Small Text..."
onChange=${(e) => setAttributes({smallText: e.target.value})}>
</textarea>
</h3>
</div>
</div>
<div className="factoid__bracket-two"></div>
</a>
</div>
</div>
`
}
57 changes: 57 additions & 0 deletions src/editor/lib/blocks/ucd-theme-factoid/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { UCDIcons } from "../../utils";
import Edit from './edit';

const name = 'ucd-theme/factoid';
const settings = {
api_version: 2,
title: "Factoid",
description: "Highlight a fact or statistic with an icon and color.",
icon: UCDIcons.renderPublic('fa-percent'),
category: 'ucd-links',
keywords: [ 'link', 'icon', 'color' ],
supports: {
"html": false,
"customClassName": false
},
attributes: {
bigText: {
type: 'string',
default: ''
},
smallText: {
type: 'string',
default: ''
},
href: {
type: 'string',
default: ''
},
postId: {
type: 'number',
default: 0
},
taxId: {
type: 'number',
default: 0
},
newTab: {
type: "boolean",
default: false
},
icon: {
type: 'string',
default: 'ucd-public:fa-percent'
},
brandColor: {
type: "string",
default: ""
},
brackets: {
type: "boolean",
default: false
}
},
edit: Edit
};

export default { name, settings };
2 changes: 1 addition & 1 deletion src/editor/lib/blocks/ucd-theme-photo-card/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default ( props ) => {
<${ToolbarColorPicker}
onChange=${onColorChange}
value=${attributes.brandColor}
ucdBlock="tile-link"
ucdBlock="photo-card"
/>
<${ToolbarSectionDisplay}
sections=${cardSections}
Expand Down
14 changes: 14 additions & 0 deletions src/public/scss/temp.scss
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,18 @@ hr.y2 {
transition: all .3s ease-in-out;
}

// factoid
.factoid__icon {

display: flex;
justify-content: center;

ucdlib-icon {
width: 2em;
height: 2em;
min-width: 2em;
min-height: 2em;
}
}


7 changes: 7 additions & 0 deletions theme/includes/classes/block-transformations.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public static function getPosts($attrs=array()){
return $attrs;
}

public static function setDefaultFactoidIcon($attrs){
if ( !array_key_exists('icon', $attrs) ) {
$attrs['icon'] = 'ucd-public:fa-percent';
}
return $attrs;
}

/**
* If page is in primary nav, returns its children
* If page is part of hierarchy, return its children
Expand Down
5 changes: 5 additions & 0 deletions theme/includes/classes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ function __construct($editor_script_slug, $settings=array()) {
"twig" => "@ucd/blocks/contact-list.twig",
"transform" => array("formatContactList")
),
"ucd-theme/factoid" => array(
"twig" => "@ucd/blocks/factoid.twig",
"hasBrandColors" => true,
"transform" => array("getPermalink", "setDefaultFactoidIcon")
),
"ucd-theme/faq" => array(
"twig" => "@ucd/blocks/faq.twig",
"transform" => array("addSpacing")
Expand Down
4 changes: 3 additions & 1 deletion theme/includes/classes/customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ public function colors($wp_customize){
array("slug" => "heading-with-icon", "label" => "Heading With Icon Palette"),
array("slug" => "separator", "label" => "Separator Palette"),
array("slug" => "object-box", "label" => "Object Box Border Palette"),
array("slug" => "tile-link", "label" => "Tile Link Palette")
array("slug" => "tile-link", "label" => "Tile Link Palette"),
['slug' => 'factoid', 'label' => 'Factoid Palette'],
['slug' => 'photo-card', 'label' => 'Photo Card Palette']
);
$blocks_with_colors = apply_filters( 'ucd-theme/customizer/block-colors', $blocks_with_colors );
foreach ($blocks_with_colors as $block) {
Expand Down
5 changes: 5 additions & 0 deletions views/blocks/factoid.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% from getUcdMacro('links') import factoid %}
{% if attributes.permalink %}
{% set attributes = attributes|merge({'href': attributes.permalink}) %}
{% endif %}
{{ factoid(attributes) }}
41 changes: 41 additions & 0 deletions views/macros/links.twig
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,47 @@ kwargs:
</a>
{% endmacro %}

{#
http://webstyleguide.ucdavis.edu/?p=molecules-factoid-brackets
kwargs:
href {String}: link
icon {String}: icon parameter of a ucdlib-icon element
bigText {String}: Text to display below icon
smallText {String}: Text to display below bigText
brandColor {String} - UCD alt color slug
newTab {Boolean} - If link opens in new tab
brackets {Boolean} - If true, the icon will be displayed in brackets
#}
{% macro factoid( kwargs={} ) %}
{% set classes = ['factoid'] %}
{% if kwargs.brandColor %}
{% set classes = classes|merge(['category-brand--' ~ kwargs.brandColor]) %}
{% endif %}
{% if kwargs.brackets %}
{% set classes = classes|merge(['factoid--brackets']) %}
{% endif %}
{% set classes = classes|join(' ') %}

{% set target = kwargs.newTab ? "target='_blank'" : "" %}
{% set icon = kwargs.icon ? kwargs.icon : 'ucd-public:fa-percent' %}

<div class="{{classes}}">
<a class="factoid__link" href="{{kwargs.href}}" {{target}}>
<div class="factoid__bracket-one"></div>
<div class="factoid__bracket-wrapper">
<div class="factoid__figure factoid__icon">
<ucdlib-icon icon="{{icon}}"></ucdlib-icon>
</div>
<div class="factoid__body">
<h2 class="factoid__big-text">{{kwargs.bigText}}</h2>
<h3 class="factoid__small-text">{{kwargs.smallText}}</h3>
</div>
</div>
<div class="factoid__bracket-two"></div>
</a>
</div>
{% endmacro %}

{#
http://dev.webstyleguide.ucdavis.edu/redesign/?p=molecules-focal-link-icon
kwargs:
Expand Down

0 comments on commit 284c3fd

Please sign in to comment.