diff --git a/.editorconfig b/.editorconfig index 1d658f5d..2cbaaa17 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,7 +13,7 @@ insert_final_newline = true trim_trailing_whitespace = true indent_style = tab -[*.{js}] +[*.{js,scss}] indent_style = space indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js index 413f81e1..9e26051a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,7 +5,7 @@ module.exports = { root: true, parser: '@typescript-eslint/parser', parserOptions: { - project: [ './jsconfig.json', 'jsconfig.eslint.json' ], + project: [ './tsconfig.json', 'tsconfig.eslint.json' ], }, extends: [ 'plugin:@wordpress/eslint-plugin/recommended' ], settings: { @@ -15,7 +15,7 @@ module.exports = { 'import/resolver': { typescript: { alwaysTryTypes: true, - project: [ './jsconfig.json', 'jsconfig.eslint.json' ], + project: [ './tsconfig.json', 'tsconfig.eslint.json' ], }, }, }, diff --git a/.lintstagedrc b/.lintstagedrc index 8444a777..cc18341a 100644 --- a/.lintstagedrc +++ b/.lintstagedrc @@ -1,5 +1,6 @@ { "**/*.(json|yml|yaml)": "prettier --write", + "**/*.(css|scss|sass)": "stylelint --fix", "**/*.(js|jsx|cjs|mjs|ts|tsx)": "eslint --ext .js,.jsx,.cjs,.mjs,.ts,.tsx --fix", "**/*.php": "php vendor/bin/phpcbf --standard=phpcs.xml.dist -s --report=summary" } diff --git a/.stylelintrc b/.stylelintrc new file mode 100644 index 00000000..8b9eb42a --- /dev/null +++ b/.stylelintrc @@ -0,0 +1,3 @@ +{ + "extends": [ "@wordpress/stylelint-config/scss" ] +} diff --git a/includes/demo.php b/includes/demo.php index d28bc33f..4cabd51d 100644 --- a/includes/demo.php +++ b/includes/demo.php @@ -11,7 +11,7 @@ use WP_List_Table; /** - * Adds WP Notify icon after the user avatar in the top admin bar in the "secondary" position + * Adds WP Notifications icon after the user avatar in the top admin bar in the "secondary" position * * @param WP_Admin_Bar $wp_admin_bar Toolbar instance. */ @@ -20,22 +20,11 @@ function admin_bar_item( WP_Admin_Bar $wp_admin_bar ) { return; } - $aside = sprintf( - '', - __( 'Notifications' ) - ); - $args = array( - 'id' => 'wp-notify', - 'title' => sprintf( "%s", __( 'Notifications' ) ), + 'id' => 'wp-notification-hub', + 'title' => __( 'loading' ), 'parent' => 'top-secondary', 'meta' => array( - 'html' => $aside, 'tabindex' => 0, ), ); @@ -44,30 +33,31 @@ function admin_bar_item( WP_Admin_Bar $wp_admin_bar ) { add_action( 'admin_bar_menu', '\WP\Notifications\admin_bar_item', 1 ); /** - * Adds WP Notify area at the top of the dashboard + * Adds WP Notifications area at the top of the dashboard */ function admin_notice() { - echo '
'; + echo ''; } add_action( 'admin_notices', '\WP\Notifications\admin_notice' ); /** - * Register and enqueue a wp notify scripts and stylesheet in WordPress admin. + * Register and enqueue a wp-notifications scripts and stylesheet in WordPress admin. */ function enqueue_admin_assets() { /* Load styles */ - wp_register_style( 'wp_notify_css', WP_FEATURE_NOTIFICATION_PLUGIN_DIR_URL . '/build/wp-notify.css', array(), WP_FEATURE_NOTIFICATION_PLUGIN_VERSION ); - wp_enqueue_style( 'wp_notify_css' ); + wp_register_style( 'wp_notifications', WP_FEATURE_NOTIFICATION_PLUGIN_DIR_URL . '/build/wp-notifications.css', array(), WP_FEATURE_NOTIFICATION_PLUGIN_VERSION ); + wp_enqueue_style( 'wp_notifications' ); /* Load scripts */ - $asset = include WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/build/wp-notify.asset.php'; - wp_register_script( 'wp_notify_js', WP_FEATURE_NOTIFICATION_PLUGIN_DIR_URL . '/build/wp-notify.js', $asset['dependencies'], WP_FEATURE_NOTIFICATION_PLUGIN_VERSION, true ); - wp_enqueue_script( 'wp_notify_js' ); + $asset = include WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/build/wp-notifications.asset.php'; + wp_register_script( 'wp_notifications', WP_FEATURE_NOTIFICATION_PLUGIN_DIR_URL . '/build/wp-notifications.js', $asset['dependencies'], WP_FEATURE_NOTIFICATION_PLUGIN_VERSION, true ); + wp_enqueue_script( 'wp_notifications' ); + wp_localize_script( - 'wp_notify_js', - 'wp_notify_data', + 'wp_notifications', + 'wp_notifications_data', array( - 'settingsPage' => esc_url( admin_url( 'options-general.php?page=wp-notify' ) ), + 'settingsPage' => esc_url( admin_url( 'options-general.php?page=notifications' ) ), ) ); } @@ -81,7 +71,7 @@ function enqueue_admin_assets() { * @return void */ function add_admin_options_page() { - add_options_page( 'Notifications', 'Notifications', 'manage_options', 'wp-notify', '\WP\Notifications\render_admin_options_page' ); + add_options_page( 'Notifications', 'Notifications', 'manage_options', 'notifications', '\WP\Notifications\render_admin_options_page' ); } add_action( 'admin_menu', '\WP\Notifications\add_admin_options_page' ); @@ -233,7 +223,7 @@ function init_table() { * Registers our dashboard widget. */ function dashboard_widget() { - add_meta_box( 'wp_notify', __( 'WP Notify' ), '\WP\Notifications\render_dashboard_widget', 'dashboard', 'side', 'high' ); + add_meta_box( 'wp_notifications', __( 'WP Notifications Feature' ), '\WP\Notifications\render_dashboard_widget', 'dashboard', 'side', 'high' ); } add_action( 'wp_dashboard_setup', '\WP\Notifications\dashboard_widget' ); @@ -257,8 +247,8 @@ function render_dashboard_widget() {
-
-
+
+
- { source } { '\u2022 ' } - { moment( date ).fromNow() } -
-); +/** + * @typedef {import('../store').Notice} Notice + */ /** * It renders a single notice * - * @param {Object} props + * @param {Notice} props * @return {JSX.Element} Notice - the single notice */ export const Notice = ( props ) => { const { - id, - title, - status, + action, context = defaultContext, - source = 'WordPress', - date = __( 'Just now' ), + date = nowInSeconds(), + dismissLabel, + dismissible, + icon, + id, message, severity, - dismissible, - unread, + source = 'WordPress', + status, + title, } = props; /** @@ -49,9 +49,12 @@ export const Notice = ( props ) => { function dismissNotice() { dispatch( NOTIFY_NAMESPACE ).updateNotice( { id, - status: 'dismissing', + status: 'dismissed', } ); - dispatch( NOTIFY_NAMESPACE ).removeNotice( id ); + // TODO missing exit animation + delay( 500 ).then( () => + dispatch( NOTIFY_NAMESPACE ).removeNotice( id ) + ); } return ( @@ -59,27 +62,29 @@ export const Notice = ( props ) => { className={ classnames( 'wp-notification', 'wp-notice-' + id, - dismissible, + dismissible ? 'dismissible' : null, severity ? severity : null, - unread ? 'unread' : null, status ) } >{ props.message }
-