summaryrefslogtreecommitdiff
path: root/app/FontAwesome.php
blob: 61178f11aa5179e984a74045487a31c4d850100d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
 * webtrees: online genealogy
 * Copyright (C) 2017 webtrees development team
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

namespace Fisharebest\Webtrees;

/**
 * Helper functions to generate markup for FontAwesome.
 *
 * @link http://fontawesome.io/accessibility
 */
class FontAwesome extends Html {
	/** Which font-awesome icon to use for which action/entity */
	const ICONS = [
		// Application icons
		'add'                => 'fa fa-plus wt-icon-add',
		'calendar'           => 'fa fa-calendar wt-icon-calendar',
		'cancel'             => 'fa fa-close wt-icon-cancel',
		'coordinates'        => 'fa fa-map-marker wt-icon-coordinates',
		'copy'               => 'fa fa-copy wt-icon-copy',
		'delete'             => 'fa fa-trash-o wt-icon-delete',
		'download'           => 'fa fa-download wt-icon-download',
		'edit'               => 'fa fa-pencil wt-icon-edit',
		'help'               => 'fa fa-info-circle wt-icon-help',
		'email'              => 'fa fa-envelope-o wt-icon-email',
		'keyboard'           => 'fa fa-keyboard-o wt-icon-keyboard',
		'pin'                => 'fa fa-thumb-tack wt-icon-pin',
		'preferences'        => 'fa fa-wrench wt-icon-preferences',
		'search'             => 'fa fa-search wt-icon-search',
		'save'               => 'fa fa-check wt-icon-save',
		'warning'            => 'fa fa-warning wt-icon-warning',
		// Arrows (start/end variants require fontawesome-rtl library)
		'arrow-down'         => 'fa fa-arrow-down wt-icon-arrow-down',
		'arrow-end'          => 'fa fa-arrow-end wt-icon-arrow-end',
		'arrow-start'        => 'fa fa-arrow-start wt-icon-arrow-start',
		'arrow-up'           => 'fa fa-arrow-up wt-icon-arrow-up',
		// GEDCOM records
		'family'             => 'fa fa-users wt-icon-family',
		'individual'         => 'fa fa-user wt-icon-individual',
		'note'               => 'fa fa-sticky-note-o wt-icon-note',
		'media'              => 'fa fa-file-imate-o wt-icon-media',
		'repository'         => 'fa fa-institution wt-icon-repository',
		'source'             => 'fa fa-file-text-o wt-icon-source',
		'submitter'          => 'fa fa-user-o wt-icon-submitter',
		'upload'             => 'fa fa-upload wt-icon-upload',
		// External sites and applications
		'bing-maps'          => 'fa fa-icon-map-o wt-icon-bing-maps',
		'google-maps'        => 'fa fa-icon-map-o wt-icon-google-maps',
		'openstreetmap'      => 'fa fa-icon-map-o wt-icon-openstreetmap',
	];

	/**
	 * Generate a decorative icon.
	 *
	 * These icons are shown in addition to other text, and should be ignored
	 * by assistive technology.
	 *
	 * @param string   $icon       The icon to show
	 * @param string[] $attributes Additional HTML attributes
	 *
	 * @return string
	 */
	public static function decorativeIcon($icon, $attributes = []) {
		$attributes['class']       = self::ICONS[$icon];
		$attributes['aria-hidden'] = 'true';

		return '<i ' . self::attributes($attributes) . '></i>';
	}

	/**
	 * Generate a semantic icon.
	 *
	 * These icons convey meaning, such as status/type/mode, and need
	 * to allow assistive technology to display this meaning.
	 *
	 * @param string   $icon       The icon to show
	 * @param string   $title      The meaning of the icon
	 * @param string[] $attributes Additional HTML attributes
	 *
	 * @return string
	 */
	public static function semanticIcon($icon, $title, $attributes = []) {
		$attributes['title'] = $title;

		return self::decorativeIcon($icon, $attributes) . '<span class="sr-only">' . $title . '</span>';
	}

	/**
	 * Generate a link icon.
	 *
	 * @param string   $icon       The icon to show
	 * @param string   $title      The meaning of the icon
	 * @param string[] $attributes Additional HTML attributes
	 *
	 * @return string
	 */
	public static function linkIcon($icon, $title, $attributes = []) {
		$attributes['aria-label'] = strip_tags($title);

		return '<a ' . self::attributes($attributes) . '>' . self::decorativeIcon($icon, ['title' => $title]) . '</a>';
	}
}